02.reactive 全家桶
  • 用来绑定复杂的数据类型 如 对象 数组
  • 无需 .value 操作

基本使用

<template>
 <div>this is hello world</div>
 <h1>{{ obj.name }}</h1>
</template>
<script setup lang="ts">
import {reactive} from "vue"
const obj = reactive({name:'zhangsan'})
</script>

readonly 转为只读对象

<template>
 <div>this is hello world</div>
 <h1>{{ obj.name }}</h1>
</template>
<script setup lang="ts">
import {reactive,readonly } from "vue"
const obj = reactive<any>({name:'zhangsan'})
const read = readonly(obj);
read.name = "lisi" //lloWorld.vue:9 [Vue warn] Set operation on key "name" failed: target is readonly.
</script>

浅层响应式 shallowReactive

用法用 reactive ,只能劫持第一层的对象

<template>
 <div>this is hello world</div>
 <h1>{{ data.user.name }}</h1>
 <button @click="handelClick">click</button>
</template>
<script setup lang="ts">
import {shallowReactive} from "vue"
const data = shallowReactive<any>({user:{name:"zhangsan"}})
const handelClick = ()=>{
 data.user.name = "lisi"
}
</script>
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇