当前位置:网站首页>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>
边栏推荐
- JNA learning notes 1: Concepts
- QQ medicine, Tencent ticket
- Talk about pseudo sharing
- MySQL入门尝鲜
- Drawerlayout suppress sideslip display
- Summary of import, export, backup and recovery of mongodb
- 如何让join跑得更快?
- Esp32 construction engineering add components
- High end for 8 years, how is Yadi now?
- Shell batch file name (excluding extension) lowercase to uppercase
猜你喜欢
Enregistrement de la navigation et de la mise en service du robot ROS intérieur (expérience de sélection du rayon de dilatation)
Use of polarscatter function in MATLAB
Introduce six open source protocols in detail (instructions for programmers)
Milkdown control icon
JS slow motion animation principle teaching (super detail)
MATLAB中polarscatter函数使用
[learning notes] zkw segment tree
Getting started with cinnamon applet
About the problem of APP flash back after appium starts the app - (solved)
PAcP learning note 1: programming with pcap
随机推荐
Mongodb command summary
error LNK2019: 无法解析的外部符号
How to make join run faster?
PAcP learning note 3: pcap method description
Clion mingw64 Chinese garbled code
Some principles of mongodb optimization
Final review notes of single chip microcomputer principle
靠卖概念上市,认养一头牛能走多远?
Summary of import, export, backup and recovery of mongodb
Server to server (S2S) event (adjust)
MongoDB命令汇总
Vscode编辑器ESP32头文件波浪线不跳转彻底解决
Esp32 construction engineering add components
MySQL error 28 and solution
How to make the new window opened by electorn on the window taskbar
Read PG in data warehouse in one article_ stat
Custom thread pool rejection policy
RecyclerView的数据刷新
LIS 最长上升子序列问题(动态规划、贪心+二分)
OSI seven layer model