// ./store/global.js OR you can use any name for js file
export const state = () => ({
loader: false,
})
export const mutations = {
setLoader(state, bool) {
state.loader = bool
},
}
export const getters = {
getLoader: state => state.loader,
}
// get variable from store
computed: {
loader(){ return this.$store.getters['global/getLoader'] },
}
// set value for loader
this.$store.commit('global/setLoader', true)
// for example if you will work in other store files ./store/requests.js and you need to change loader value you can use this code
export const actions = {
someRequest({commit, state, dispatch}){
this.commit('global/setLoader', true)
setTimeout(() => {
this.commit('global/setLoader', false)
}, 2000)
},
}
2条答案
按热度按时间brgchamk1#
没什么不同你不会显著改变它。
你所要做的就是把它放到单独的js文件中,然后稍微重写一下:
将其命名为index.js并将其放入“store”文件夹。就这样。就像以前那样用。别激动
z18hc3ub2#