美文网首页
对从vuex里面拿出来的数据进行循环报错,要如何解决

对从vuex里面拿出来的数据进行循环报错,要如何解决

作者: 洛禾sunshime | 来源:发表于2019-04-12 09:57 被阅读0次

报错: image.png

源码:从vuex中拿出history里面的Items数组,然后对其进行遍历,结果报了上面的错误

对应的vue文件

    ...mapState({
      history: state => state.history.all
    }),

    currStatus() {
      return this.history.status;
    }
  },
  watch: {
    currStatus(value) {
      if (this.currStatus == 1) {
        let that = this;
        let arr = [];
        // 状态监测
        console.log("that.history--->", that.history);
        arr = that.history.Items;
        for (let i = 0; i < arr.length; i++) {
          const item = arr[i];
          if (item.TId) {
            that.TIds.push(item.TId);
          }
          if (item.EId) {
            that.EIds.push(item.EId);
          }
        }

对应的store文件

import history from './../../../../api/AppService/SampleCard/History'
// initial state
const state = {
    all: {
      status:-1,      //  1:正常返回结果,2:接口异常,3:网络异常   
      code: "",
      Items:[]
    }, 
    params:{   
        Begin:'',
        End :'',
        Next_Date:'',
        TIds:'',
        EIds:''
    }, 
    type:true,   
}

  // getters
  const getters = {}
  
  // actions
  const actions = {
    history ({ commit }) {
        history.History((tools) => {
          commit('sethistory',tools)
      },state.params,state.type);
    }
  }
  
  // mutations
  const mutations = {
    sethistory (state, tools) {
      state.all.status = tools.status;
      if(state.all.status == 1){
        state.all.Items = tools.Items;
      }
    },
    setParams(state,params){        //设置参数
      state.params = params;
    },
    setStatus(state,status){
        state.all.status = status;
    },
    setType(state,type){
      state.type = type;
    },
    setAll(state,all){
      state.all = all;
    }
  }

求解!!!!

相关文章

网友评论

      本文标题:对从vuex里面拿出来的数据进行循环报错,要如何解决

      本文链接:https://www.haomeiwen.com/subject/hteqwqtx.html