1. 清除某个数组或者对象中的数据
//数组清空方式
this.array = []
//清空对象的方式
for(let i in object){
object[i] = ''
}
//或者
Object.keys(this.form).forEach((key) => (this.form[key] = ""));
2. 重置组件data内部的所有数据
Object.assign(this.$data, this.$options.data());
如果你再data中获取了router的传值:this. r o u t e . q u e r y ,用 t h i s . route.query,用this. route.query,用this.options.data()重置组件data时,data()里用this获取的props或method都为undefined 解决办法如下
Object.assign(this.$data, this.$options.data.call(this));