ts中如何访问到vue3中已有的ref和reavtive变量
在ts中访问vue3中已有的ref和reactive变量,需要先导入相应的API:
import { ref, reactive } from 'vue';
然后可以使用这些变量:
const count = ref(0);
const state = reactive({
message: 'Hello Vue!',
count: count.value,
});
console.log(state.message);
console.log(state.count);
count.value++;
console.log(state.count);
注意:由于ref和reactive返回的是一个包装后的对象,因此需要使用.value属性来访问其值。
原文地址: https://www.cveoy.top/t/topic/b1lT 著作权归作者所有。请勿转载和采集!