当前位置:网站首页>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,
边栏推荐
- Two global variables__ Dirname and__ Further introduction to common functions of filename and FS modules
- Cross domain transfer learning of professional skill word extraction in Chinese recruitment documents
- HYDAC溢流阀DB08A-01-C-N-500V
- LT7911D Type-C/DP转mipi 方案成熟可提供技术支持
- Standard C language learning summary 10
- 怎样巧用断言+异常处理类,使代码更简洁!(荣耀典藏版)
- 小程序开发需要什么技术
- 基于属性词补全的武器装备属性抽取研究
- 什么是质因数,质因数(素因数或质因子)在数论里是指能整除给定正整数的质数
- Pyqt5 rapid development and actual combat 5.4 web page interaction
猜你喜欢

msfvenom制作主控与被控端

Zhuzhou Jiufang middle school carried out drowning prevention and fire safety education and training activities

Vimtutor编辑

微信小程序开发入门,自己开发小程序

Mesh data generation function meshgrid

基于属性词补全的武器装备属性抽取研究

I have been in the industry for 4 years and changed jobs twice. I have understood the field of software testing~

系统分析师
![Introduction to C language [detailed]](/img/ac/9ba2e298faabd8dc4c76575ea182d1.png)
Introduction to C language [detailed]

Storage and steps of phospholipid coupled antibody / protein Kit
随机推荐
从 Web3到Web2.5,是倒退还是另辟蹊径?
What is the purpose of database read-write separation [easy to understand]
How to skillfully use assertion + exception handling classes to make the code more concise! (glory Collection Edition)
Open earphone which air conduction earphone with good sound quality and recognized sound quality is recommended
Data interpolation -- normalize data of different magnitude
HYDAC溢流阀DB08A-01-C-N-500V
如何优雅的设计工作流引擎(荣耀典藏版)
How is nanoid faster and more secure than UUID implemented? (glory Collection Edition)
什么是质因数,质因数(素因数或质因子)在数论里是指能整除给定正整数的质数
Pytorch learning record (4): over fitting, convolution neural network CNN
基于BRNN的政务APP评论端到端方面级情感分析方法
基于Xception-TD的中华传统刺绣分类模型构建
微信小程序开发入门,自己开发小程序
[brother hero July training] day 28: dynamic planning
39. 组合总和
Esp8266 Arduino programming example - deep sleep and wake up
Zhuzhou Jiufang middle school carried out drowning prevention and fire safety education and training activities
数据插值——对不同量级的数据进行归一化
Knowledge description framework of foreign patent documents based on knowledge elements
No swagger, what do I use?