当前位置:网站首页>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");
边栏推荐
猜你喜欢
MYSQL----导入导出&视图&索引&执行计划
循环肿瘤细胞——Abnova 解决方案来啦
Stack and queue-p78-8 [2011 unified examination true question]
. Net core accesses uncommon static file types (MIME types)
Abnova 膜蛋白脂蛋白体技术及类别展示
MOS tube parameters μ A method of Cox
SolidWorks的GB库(钢型材库,包括铝型材、铝管等结构)安装及使用教程(生成铝型材为例)
Leetcode t1165: log analysis
.net core 访问不常见的静态文件类型(MIME 类型)
偏执的非合格公司
随机推荐
Several index utilization of joint index ABC
JDBC database connection pool usage problem
快速定量,Abbkine 蛋白质定量试剂盒BCA法来了!
Libcurl returns curlcode description
This article introduces you to the characteristics, purposes and basic function examples of static routing
服装门店如何盈利?
【mysqld】Can't create/write to file
MOS tube parameters μ A method of Cox
Brand · consultation standardization
ip地址那点事
What books can greatly improve programming ideas and abilities?
Mysql---- import and export & View & Index & execution plan
Cloudcompare point pair selection
linux系统rpm方式安装的mysql启动失败
Matlab tips (29) polynomial fitting plotfit
sqlserver多线程查询问题
Jetpack Compose 远不止是一个UI框架这么简单~
二十岁的我4面拿到字节跳动offer,至今不敢相信
. Net 5 fluentftp connection FTP failure problem: this operation is only allowed using a successfully authenticated context
多学科融合