1.使用ref代替data 在Vue 3中,推荐使用ref来代替data。ref可以将一个普通的值转换为响应式数据。
import { ref } from 'vue';
export default {
setup() {
const count = ref(0);
function increment() {
count.value++;
}
return {
count,
increment,
};
}
}
2.使用reactive创建响应式对象 Vue 3中,可以使用reactive来创建响应式对象。
import { reactive } from 'vue';
export default {
setup() {
const state = reactive({
count: 0,
message: 'Hello, Vue 3!',
});
function increment() {
state.count++;
}
return {
state,
increment,
};
}
}
基于最新的 Vite / TypeScript / Vue3 / ElementPlus打造的前后端一体管理后台框架,免费开源,可以快速开发企业级应用
演示地址:https://demo.eleadmin.cn/