Vue缓存页面缓存数据丢失处理
伊莉雅
当添加的内容输入后,没有保存,切换了页面路由,再返回到此页面,数据内容消失了;需要保存输入的内容处理;
通过添加缓存方法添加保存
以下是部分主要代码:

主要本地存储代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| getStorage() { this.newVal = JSON.parse(localStorage.getItem('alloatAddInfo')) ? JSON.parse(localStorage.getItem('alloatAddInfo')) : {} this.basic = this.newVal this.buyerName = this.newVal.buyerName ? this.newVal.buyerName : '' this.tableData = this.newVal.itemInfo && this.newVal.itemInfo.length > 0 ? this.newVal.itemInfo : [{ id: 0, type: 'custom' }] }, watchStorage(data) { const params = { ...data } localStorage.setItem('alloatAddInfo', JSON.stringify(params)) },
|