当前位置:   article > 正文

Element Ui 切换页面后刷新,数据清空,缓存处理;_element 框架 navbar 切换页面清空表单问题

element 框架 navbar 切换页面清空表单问题

实现需求如下图所示:

当添加的内容输入后,没有保存,切换了页面路由,再返回到此页面,数据内容消失了;需要保存输入的内容处理;

方法一、通过添加缓存方法添加保存;以下是部分主要代码:

主要本地存储代码

  1. // 取缓存
  2. getStorage() {
  3. this.newVal = JSON.parse(localStorage.getItem('alloatAddInfo')) ? JSON.parse(localStorage.getItem('alloatAddInfo')) : {}
  4. // 根据需求赋值
  5. this.basic = this.newVal
  6. this.buyerName = this.newVal.buyerName ? this.newVal.buyerName : ''
  7. this.tableData = this.newVal.itemInfo && this.newVal.itemInfo.length > 0 ? this.newVal.itemInfo : [{
  8. id: 0,
  9. type: 'custom'
  10. }]
  11. },
  12. // 监听添加缓存
  13. watchStorage(data) {
  14. const params = {
  15. ...data
  16. }
  17. localStorage.setItem('alloatAddInfo', JSON.stringify(params))
  18. },

以上内容仅供参考!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/113057
推荐阅读
相关标签
  

闽ICP备14008679号