I have just been in contact with vue for a week, and my understanding of vuex is a little vague. Here is the vuex / moudles / com.js I used in the project. Can I write it this way? Is there anything wrong in understanding?
import * as types from "../type"
/** Action
* vuexstatecommitmutation
* Vuex
*
* action state, state
* mutations action action state
*
* commit store state ,action
*
* computed vuex
* getters computed getters, store
*/
/*APP state*/
const state = {
showSuccess: true,
showFail: false,
toastMsg: "",
showToast: false
}
/* state action*/
const actions = {
showToast({commit}, state){
commit(types.COM_SHOE_TOAST, state)
},
showSuccess({commit}, state){
commit(types.COM_SHOW_SUCCESS, state)
},
showFail({commit}, state){
commit(types.COM_SHOW_FAIL, state)
},
toastMsg({commit},str){
commit(types.COM_TOAST_MSG, str)
}
}
/**/
const getters = {
showToast: state => state.showToast
}
/* state*/
const mutations = {
[types.COM_SHOE_TOAST](state, status){
state.COM_SHOE_TOAST = status
},
[types.COM_SHOW_SUCCESS](state, status){
state.COM_SHOW_SUCCESS = status
},
[types.COM_SHOW_FAIL](state, status){
state.COM_SHOW_FAIL = status
},
[types.COM_TOAST_MSG](state, str){
state.COM_TOAST_MSG = str
}
}
/**/
export default {
state,
actions,
getters,
mutations
}
How to write in store.js? The above is a component of toast, which has not been implemented yet.