0%

JS vue3 reactive 重新赋值的问题

Object.assign

这个最方便

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

直接用 ref

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

直接用 reactive

1
2
3
let obj = reactive({ a: {} });

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

toRefs

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

参考文章