vuex 公共数据存储
vuex 公共数据存储, 简单介绍一下怎么使用的(这是主要是配上一篇 Axios 请求配置统一封装(加入缓存机制))
代码如下
:
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export default new Vuex.Store({ state, mutations, actions });
// actions
export default {
setChangeStorageHistory (context, value) {
context.commit('setChangeStorageHistory', value)
},
setEmptyStorageHistory (context) {
context.commit('setEmptyStorageHistory')
}
};
// mutations
export default {
setChangeStorageHistory (state, value) {
const historyList = state.storageHistory;
historyList.push(value);
state.storageHistory = historyList;
},
setEmptyStorageHistory (state) {
state.storageHistory = [];
},
set_searchValue (state, payload) {
state.searchValue = payload;
}
};
// state
export default {
storageHistory: [],
searchValue: ''
};
tiryLi