This is how the loading state is generally used in Vue
getData(){ this.loading = true; get(api).then(res => { this.data = res; this.loading = false; }) }
But how to use it in the vuex action? The following example uses a public loading and found that it does not work. The loading state should be local. So how to control the loading state in vuex?
const actions = { getProductInfo({commit}){ commit(types.LOADING, true) api.xxx() .then(res => { commit(types.PRODUCTINFO, res.data) commit(types.LOADING, false) }) },
Following your second example,
put the loading flag in the state, and the component gets whether it is loading through the state