vue xxx.find is not a function;

错误:1.后端获取数据集合,存到 vuex store 中和本地 window.localStorage;

   2.因为要解决刷新丢失问题在routeconfig中路由拦截重新 拿到本地数据window.localStorage 保存到store中;

   3.界面刷新报错:vue xxx.find is not a function

分析:1.xxx类型确实不是数组;

   2.因为在存储本地的时候,数据类型为string; 在重新赋值到本地的时候变为了string; 

解决:一、在用到的时候用array.from(xxxx); 可以解决;

          二、在存储的时候做一个判断重新用json parse();如下图所示:

    saveSysDicList(state, data) {
              if(typeof data ==='string' && data!='undefined')
              {
                  state.sysDicList =JSON.parse( data);
              }
              else
              {
                  state.sysDicList = data;
                  window.localStorage.setItem("SysDicList", JSON.stringify(data));
              }
          }
posted @ 2024-04-02 16:04  cdxy2005  阅读(10)  评论(0编辑  收藏  举报