import { defineComponent, ref, reactive, toRefs } from 'vue';
export default defineComponent({
name: 'about',
setup() {
const msg = ref('This is an about page');
const obj = reactive({
a: 1,
b: 2
})
const msgValue = ()=>{
msg.value = 'value'; // 使用 ref 定义的 要加 .value 就可以改动
obj.a = 2; // reactive 定义的对象不须要
}
return {
msg,
obj,
...toRefs(obj), // toRefs 解构出里面每个值,模板里直接用 {{b}},
msgValue
}
},
})
toRef的作用
最新推荐文章于 2024-04-10 08:00:57 发布