Skip to content

Vue3 响应式数据重新赋值问题详解

Published: at 10:32 AMSuggest Changes

Object.assign

这个最方便

let obj = reactive({ a: {} });
Object.assign(obj,{a:2, b:3})

直接用 ref

let list = ref([{ id: 1, name: 'Andy' }]);
const checkBtn = () => {
  list.value = [{ id: 1, name: 'Andy' }];
  list.value.push({ id: 2, name: 'Lucy' });
};

直接用 reactive

let obj = reactive({ a: {} });

obj.a = { ...obj.a, ...newdata };

toRefs

看文档:https://vuejs.org/api/reactivity-utilities.html#torefs

参考文章


Previous Post
JS Vue React 路由处理机制
Next Post
Vue 子组件如何获取所有父组件传递的值