在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ vuex數(shù)據(jù)更新有延遲,求解?

vuex數(shù)據(jù)更新有延遲,求解?

store/module/work.js

import * as types from '../mutation-types'
import * as api from '@/api/work.js';
const state = {
    flowTypeListData:[],
}
const getters = {
    flowFormData: state => state.flowFormData,
}
const actions = {
    //分類列表
    getFlowTypeList({ commit }) {
        api.getFlowTypeList().then(response => {
            commit(types.FLOW_TYPE_LIST, response.data)
        })
    },
    //新增分類
    addFlowType({ commit }, data) {
        api.addFlowType(data).then(response => {
            commit(types.ADD_FLOW_TYPE, response.data)
        })
    }
}
const mutations = {
    [types.FLOW_TYPE_LIST](state, data) {
        state.flowTypeListData = data;
    },
    [types.ADD_FLOW_TYPE](state, data) {
        if(data == 1){
            console.log("創(chuàng)建成功");
        }else{
            console.log("創(chuàng)建失敗");
        }
    },
}
export default {
    state,
    getters,
    actions,
    mutations
}

views/type.vue

import { mapActions, mapGetters } from "vuex";
export default {
  data() {
    return {
      formData: {}, 
    }
  },
  created() {
    this.$store.dispatch("getFlowTypeList");
  },
  computed: {
    ...mapGetters({
      data: "flowTypeListData",
    })
  },
  mounted() {},
  methods: {
    save(){
      //提交創(chuàng)建的分類數(shù)據(jù)
      this.$store.dispatch("addFlowType",this.formData);
      //更新分類列表  ###問(wèn)題:界面數(shù)據(jù)沒(méi)有實(shí)時(shí)更新,刷新界面數(shù)據(jù)才在界面上出來(lái)
      this.$store.dispatch("getFlowTypeList");
    }
  },

  components: {  }
};

以上代碼都可以正常運(yùn)行,只是有更新延遲問(wèn)題;

問(wèn)題:界面數(shù)據(jù)沒(méi)有實(shí)時(shí)更新,刷新界面數(shù)據(jù)才在界面上出來(lái),我試了好久,然后發(fā)現(xiàn)如果在 this.$store.dispatch("getFlowTypeList"); 包裹一個(gè)setTimeout 就可以實(shí)時(shí)更新界面數(shù)據(jù),以前不用VUEX的時(shí)候沒(méi)有發(fā)現(xiàn)這種問(wèn)題,大家遇到這種問(wèn)題嗎,如何解決的?

回答
編輯回答
柒喵

只有加loading了

2017年2月20日 04:50
編輯回答
柚稚

更新分類列表的action必須等添加分類的action中的異步請(qǐng)求完成后才能dispatch

2017年9月7日 02:13