当前位置:网站首页>Toraw and markraw
Toraw and markraw
2022-07-07 13:31:00 【The sea is only dark blue】
toRaw Will a reactive Turn the generated responsive object into a normal object
markRaw Mark an object , So that it will never be a responsive object again
vue3 in , use ref、reactive Defining data , In order to put ordinary data , Become responsive data
Some of the time , You need to put responsive data , And then become ordinary data , Use... At this time toRaw
<script lang="ts" setup>
import {
ref, reactive, toRaw, markRaw } from 'vue'
const person = reactive({
name: ' ha-ha ',
age: 10,
job: {
salary: 20
}
})
console.log(person) // proxy Responsive data
const p = toRaw(person)
console.log(p) // object Common data
const sum = ref(0)
const s = toRaw(sum)
console.log(s) // undefined because toRaw Can only handle reactive Defined responsive data
</script>
setup Throughout the work , Call it once ;
When the need has been defined reactive When adding an attribute to the data , This attribute will also become responsive , But if I add it, I don't want it to become responsive , use markRaw
<script lang="ts" setup>
import {
ref, reactive, toRaw, markRaw } from 'vue'
const person = reactive({
name: ' ha-ha ',
age: 10,
job: {
salary: 20
}
})
let car = {
name: ' automobile ', price: 40 }
person.car = markRaw(car) // here ,person It added car It's normal data
</script>
边栏推荐
- Mongodb slice summary
- [untitled]
- 靠卖概念上市,认养一头牛能走多远?
- MongoDB的用户管理总结
- Vscode编辑器ESP32头文件波浪线不跳转彻底解决
- DETR介绍
- Why can basic data types call methods in JS
- [dark horse morning post] Huawei refutes rumors about "military master" Chen Chunhua; Hengchi 5 has a pre-sale price of 179000 yuan; Jay Chou's new album MV has played more than 100 million in 3 hours
- Vscade editor esp32 header file wavy line does not jump completely solved
- Distributed transaction solution
猜你喜欢
How to make join run faster?
High end for 8 years, how is Yadi now?
Custom thread pool rejection policy
Fast development board pinctrl and GPIO subsystem experiment for itop-imx6ull - modify the device tree file
Introduction and basic use of stored procedures
室内ROS机器人导航调试记录(膨胀半径的选取经验)
Navicat运行sql文件导入数据不全或导入失败
Go language learning notes - structure
提升树莓派性能的方法
error LNK2019: 无法解析的外部符号
随机推荐
Esp32 series column
线程池拒绝策略最佳实践
[untitled]
My "troublesome" subordinates after 00: not bad for money, against leaders, and resist overtime
Cinnamon taskbar speed
Detr introduction
Cinnamon 任务栏网速
[untitled]
如何让join跑得更快?
Milkdown 控件图标
JS缓动动画原理教学(超细节)
【学习笔记】线段树选做
Error lnk2019: unresolved external symbol
Go language learning notes - structure
如何让electorn打开的新窗口在window任务栏上面
[untitled]
1. Deep copy 2. Call apply bind 3. For of in differences
Split screen bug notes
单片机学习笔记之点亮led 灯
[dark horse morning post] Huawei refutes rumors about "military master" Chen Chunhua; Hengchi 5 has a pre-sale price of 179000 yuan; Jay Chou's new album MV has played more than 100 million in 3 hours