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("");
}else{
console.log("");
}
},
}
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(){
//
this.$store.dispatch("addFlowType",this.formData);
// -sharp-sharp-sharp:
this.$store.dispatch("getFlowTypeList");
}
},
components: { }
};
all of the above codes can run normally, but there is a problem of update delay.
question: the interface data is not updated in real time, so the refresh interface data comes out on the interface. I tried it for a long time, and then found that if I was in this.$store.dispatch ("getFlowTypeList"); if I wrapped a setTimeout, I could update the interface data in real time. Before, I didn"t find this kind of problem when I didn"t use VUEX. Do you encounter this problem and how do you solve it?