当前位置:网站首页>toRaw和markRaw
toRaw和markRaw
2022-07-07 11:29:00 【湛海不过深蓝】
toRaw 将一个reactive生成的响应式对象转为普通对象
markRaw 标记一个对象,使其永远不会再成为响应式对象
vue3中,用ref、reactive定义数据,是为了把普通数据,变成响应式数据
某些时候,需要将响应式数据,再变成普通数据,此时就用toRaw
<script lang="ts" setup>
import {
ref, reactive, toRaw, markRaw } from 'vue'
const person = reactive({
name: '哈哈',
age: 10,
job: {
salary: 20
}
})
console.log(person) // proxy 响应式数据
const p = toRaw(person)
console.log(p) // object 普通数据
const sum = ref(0)
const s = toRaw(sum)
console.log(s) // undefined 因为toRaw只能处理reactive所定义的响应式数据
</script>
setup 在整个工作过程中,只调用一次;
当需要在已经定义好的reactive数据里面在添加一个属性时,这个属性也会变成响应式的,可是如果我添加时就不想让他变成响应式的,用markRaw
<script lang="ts" setup>
import {
ref, reactive, toRaw, markRaw } from 'vue'
const person = reactive({
name: '哈哈',
age: 10,
job: {
salary: 20
}
})
let car = {
name: '汽车', price: 40 }
person.car = markRaw(car) // 此时,person里面添加的car就是普通数据
</script>
边栏推荐
- Practical case: using MYCAT to realize read-write separation of MySQL
- Server to server (S2S) event (adjust)
- MATLAB中polarscatter函数使用
- Read PG in data warehouse in one article_ stat
- Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
- MongoDB内部的存储原理
- Awk of three swordsmen in text processing
- How did Guotai Junan Securities open an account? Is it safe to open an account?
- LeetCode_ Binary search_ Medium_ 153. Find the minimum value in the rotation sort array
- JS function returns multiple values
猜你喜欢

Ways to improve the performance of raspberry pie

存储过程的介绍与基本使用

【学习笔记】zkw 线段树

如何让join跑得更快?

xshell连接服务器把密钥登陆改为密码登陆

Cloud detection 2020: self attention generation countermeasure network for cloud detection in high-resolution remote sensing images

How far can it go to adopt a cow by selling the concept to the market?

LIS 最长上升子序列问题(动态规划、贪心+二分)

Milkdown 控件图标

我那“不好惹”的00后下属:不差钱,怼领导,抵制加班
随机推荐
解决缓存击穿问题
centso7 openssl 报错Verify return code: 20 (unable to get local issuer certificate)
【学习笔记】AGC010
Esp32 series column
简单好用的代码规范
工具箱之 IKVM.NET 项目新进展
PCAP学习笔记二:pcap4j源码笔记
About the problem of APP flash back after appium starts the app - (solved)
ORACLE进阶(五)SCHEMA解惑
Storage principle inside mongodb
Practical example of propeller easydl: automatic scratch recognition of industrial parts
Server to server (S2S) event (adjust)
为租客提供帮助
Introduction and basic use of stored procedures
Coscon'22 community convening order is coming! Open the world, invite all communities to embrace open source and open a new world~
Getting started with cinnamon applet
MongoDB命令汇总
Simple and easy-to-use code specification
ESP32系列专栏
Esp32 ① compilation environment