当前位置:网站首页>04.toRef 默认值
04.toRef 默认值
2022-07-28 20:14:00 【@大迁世界】
这节课,我们来看一下 toRef 的默认值。
我们知道 toRef 可以用来为源响应式对象的某个 property 新创建一个 ref,然后 ref 可以被传递,它会保持对其源 property 的响应式连接。
<script setup>
import { reactive, toRef } from 'vue'
const state = reactive({
foo: 1,
bar: 2,
})
const fooRef = toRef(state, 'foo')
fooRef.value++
console.log(state.foo) // 2
state.foo++
console.log(fooRef.value) // 3
</script>
这里我们为 state 对象的 foo 属性创建一个名为 fooRef的 ref,当我们 fooRef.value++ 时,此时 state.foo 的值也跟着变,因为 toRef 会保持对其源对象属性的响应连接,所以,当 state.foo 值变化时,fooRef 的值也会跟着变。
这些点,相信大家都知道。
但 toRef 也可以提供一个默认值,这个点可能大家就比较少见了。
我们来看个例子,假设我们想为 state 对象的 car 属性创建一个名为 carRef 的 ref,
边栏推荐
- Getting started with Oracle
- 中文招聘文档中专业技能词抽取的跨域迁移学习
- Cy3/Cy5/Cy5.5/Cy7荧光标记抗体/蛋白试剂盒(10~100mg标记量)
- 凡尔赛天花板:“毕业两年月薪才35K,真是没出息啊~~”
- Pyqt5 rapid development and actual combat 5.4 web page interaction
- Lt7911d type-c/dp to Mipi scheme is mature and can provide technical support
- 什么是质因数,质因数(素因数或质因子)在数论里是指能整除给定正整数的质数
- Introduction to C language [detailed]
- Mesh data generation function meshgrid
- Mysql的B+树高度计算
猜你喜欢

msfvenom制作主控与被控端

基于Paragraph-BERT-CRF的科技论文摘要语步功能信息识别方法研究

For the first time, Chinese scientists used DNA to construct convolutional artificial neural network, which can complete 32 types of molecular pattern recognition tasks, or be used for biomarker signa
![Introduction to C language [detailed]](/img/ac/9ba2e298faabd8dc4c76575ea182d1.png)
Introduction to C language [detailed]

基于知识元的外文专利文献知识描述框架

Nano gold coupled antibody / protein Kit (20nm, 1mg/100 μ g/500 μ G coupling amount) preparation

入行4年,跳槽2次,我摸透了软件测试这一行~

What technology is needed for applet development

Mesh data generation function meshgrid

How does MySQL archive data?
随机推荐
网格数据生成函数meshgrid
这种动态规划你见过吗——状态机动态规划之股票问题(下)
基于知识元的外文专利文献知识描述框架
Divide and conquer, upload large files in pieces
二 RedisTemplate的序列和反序列化机制讲解
I have been in the industry for 4 years and changed jobs twice. I have understood the field of software testing~
蚂蚁集团境外站点 Seata 实践与探索
An end-to-end aspect level emotion analysis method for government app reviews based on brnn
Is it necessary to calibrate the fluke dtx-1800 test accuracy?
Information fusion method and application of expert opinion and trust in large group emergency decision-making based on complex network
How many tips do you know about using mock technology to help improve test efficiency?
Oracle triggers
基于属性词补全的武器装备属性抽取研究
中国科学家首次用DNA构造卷积人工神经网络,可完成32类分子模式识别任务,或用于生物标志物信号分析和诊断
Research on weapon equipment attribute extraction based on attribute word completion
What technology is needed for applet development
Professional Committee of agricultural water and soil engineering of China Association of Agricultural Engineering - 12th session - Notes
Research on the recognition method of move function information of scientific paper abstract based on paragraph Bert CRF
kubevela插件addons下载地址
Apple M1 processor details: performance and energy efficiency have doubled, and Intel Core i9 is no match!