当前位置:网站首页>toRefs API 与 toRef Api
toRefs API 与 toRef Api
2022-07-07 03:12:00 【要成为光的女人】
1.如果我们使用ES6的解构语法,对reactive 返回的对象进行解构获取值,那么之后无论是修改解构后的值,还是修改reactive 返回的state 对象,数据都不再是响应式的:
const info=reactive({
name:"jiang",
age:18
});
let {name,age}=info
2.那有咩有办法让我们解构出来的属性是响应式的呢?
- Vue为我们提供了一个toRefs的函数,可以将reactive返回的对象中的属性都转成ref;
- 那么我们再次进行解构出来的name和age 本身都是ref的;
//当我们这样来做的时候,会返回两个ref对象,它们是响应式的
let {name,age}=toRefs(info)
//1.toRefs:将reactive 对象中的所有属性都转成ref,建立链接
3.这种做法相当于info.name和refvalue之间建立了链接,任何一个修改都会引起另一个变化;
toRefs 和 toRef的区别
- toRefs:将reactive 对象中的所有属性都转成ref,建立链接
- toRef: 对其中一个属性进行转化成ref,建立连接
let {name}=info
let age=toRef(info,"age");
边栏推荐
猜你喜欢
.net 5 FluentFTP连接FTP失败问题:This operation is only allowed using a successfully authenticated context
Stack and queue-p79-10 [2014 unified examination real question]
华为机试题素数伴侣
How DHCP router works
SolidWorks的GB库(钢型材库,包括铝型材、铝管等结构)安装及使用教程(生成铝型材为例)
使用TCP/IP四层模型进行网络传输的基本流程
main函数在import语句中的特殊行为
MySQL SQL的完整处理流程
2018 Jiangsu Vocational College skills competition vocational group "information security management and evaluation" competition assignment
Config distributed configuration center
随机推荐
Big coffee gathering | nextarch foundation cloud development meetup is coming
Jetpack Compose 远不止是一个UI框架这么简单~
7天零基础能考证HCIA吗?华为认证系统学习路线分享
请教一下,监听pgsql ,怎样可以监听多个schema和table
From zero to one, I will teach you to build the "clip search by text" search service (2): 5 minutes to realize the prototype
多线程与高并发(9)——AQS其他同步组件(Semaphore、ReentrantReadWriteLock、Exchanger)
什么情况下考虑分库分表
The latest trends of data asset management and data security at home and abroad
MATLAB小技巧(30)非线性拟合 lsqcurefit
分布式id解决方案
Comment les entreprises gèrent - elles les données? Partager les leçons tirées des quatre aspects de la gouvernance des données
.net core 访问不常见的静态文件类型(MIME 类型)
mysql查看bin log 并恢复数据
循环肿瘤细胞——Abnova 解决方案来啦
How can flinksql calculate the difference between a field before and after update when docking with CDC?
Abnova循环肿瘤DNA丨全血分离,基因组DNA萃取分析
2022年全国所有A级景区数据(13604条)
MYSQL----导入导出&视图&索引&执行计划
Take you to brush (niuke.com) C language hundred questions (the first day)
Bus message bus