双向绑定的数据如何push到其他变量中并且不会随着改变而改变
第一次表达和描述问题,多一些包容哈
情景大概是这样的:
一个表单的数据在提交以后需要展示在页面的另外一个地方,类似浏览,然后清空表单,但是当我清空表单数据时候,也会导致push进去的数据被清空了
定义的绑定数据
const teachingCredentials = ref({
id:0,
name :undefined,
start_time :undefined,
validit :undefined,
subject_name :undefined,
});
//提交触发的事件
const addTeachingCredentials = () => {
let tcNum = formatTeachingCredentials();
//如果不这么做,数据就会消失
const { start_time,validit,name,subject_name } = teachingCredentials.value
const newArr = { start_time,validit,name,subject_name }
eduInfo.cert.push(newArr);
//清空数据
for( let tcInfo in teachingCredentials.value){
teachingCredentials.value[tcInfo] = undefined
}
}
我如果使用 eduInfo.cert.push(teachingCredentials.value),当清空teachingCredentials.value时候,eduInfo.cert添加的各个元素的数据就是空的,用上面的办法就可以避免,不过不知道原理,并且有没有其他方法,希望大佬指点
本作品采用《CC 协议》,转载必须注明作者和本文链接
要往对象里增加属性或者修改属性数据的时候,使用js里的 … 展开语法: