1、业务场景,在页面中,监听输入框值改变,就将值存入本地缓存。下次进入页面的时候,提醒用户还有没保存的数据,是否立即编辑。
2、代码如下:
watch: {
form: {
handler(newVal) {
this.saveForm();
},
deep: true
},
otherForm: {
handler(newVal) {
this.saveForm();
},
deep: true
}
}
methods: {
saveForm() {
let self = this;
let form = Object.assign(self.form, self.otherForm);
localStorage.setItem("form", JSON.stringify(form));
},
},
3、解决:
saveForm() {
let self = this;
let formbrefore = JSON.parse(JSON.stringify(self.form))
let form = Object.assign(formbrefore, self.otherForm);
localStorage.setItem("form", JSON.stringify(form));
},