Create store folder
1. Function: put asynchronous operations
File: actions.js
Content:
2. Function: Get data in state
File: getters.js
Content:
export const singer = state => state.singer
3. Function: Place method name
File: mutation-types.js
Content:
export const SET_SINGER = 'SET_SINGER'
4. Function: Manipulate state data
File: mutations.js
Content:
import * as types from './ mutation-types'
const mutation = {
[types.SET_SINGER](state,singer){
state.singer = singer
}
}
export default mutations
5. Function: Data
File: state.js
Content :
const state = {
singer:{}
}
export default state
6 .Function: Entry
File: index.js
Content:
import Vue from 'vue'
import Vuex from 'vuex'
import * as actions from './actions'
import * as getter from './getters'
import mutations from './mutations'
import state from './state'
import createLogger from 'vuex/dist/logger'
Vue.use(Vuex)
// When developing the environment, track each time Modification of state
const debug = process.env.NODE_ENV !== 'production'
export default new Vuex.Store({
actions,
getters,
mutations,
state,
strict: debug,
plugin: debug ? [createLogger()] : []
})
The above is the detailed content of Implement the initialization method of vuex. For more information, please follow other related articles on the PHP Chinese website!