03.to全家桶 toref / torefs / toRaw

toref

  • 原始数据不会更新视图,数据会更新
<template>
 <div>this is hello world</div>
 <h1>{{ state }}</h1>
 <button @click="handelClick">click</button>
</template>
<script setup lang="ts">
import {toRef} from "vue"
const user = {
 name:"zhangsan"
}
const state = toRef(user,"name")
const handelClick = ()=>{
 state.value = "lisi"
 console.log(state.value) // lisi 视图不会更新
}
</script>

torefs

用于解构 ref 对象

<script setup lang="ts">
import { reactive, toRefs } from 'vue'
const obj = reactive({
   name:"zhangsan"
})
let {name} = toRefs(obj)
</script>

toRaw

用于将 响应式(proxy)对象转为普通对象

<script setup lang="ts">
import { reactive, toRaw } from 'vue'
const obj = reactive({
name:"zhangsan"
})
const newObj = toRaw(obj)
</script>
暂无评论

发送评论 编辑评论


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