建立store資料夾
1.功能:放非同步操作
檔案:actions.js
內容:
2.功能:取得state裡資料
檔:getters.js
內容:
export const singer = state => state.singer
#
3.功能:放置方法名稱
##檔案:mutation-types.js內容:##export const SET_SINGER = 'SET_SINGER'
4.功能:操作state資料
檔案:mutations.js
內容:
import * as types from './ mutation-types'
const mutation = {
[types.SET_SINGER](state,singer){
state.singer = singer
#}
}
export default mutations
#5.功能:資料
檔案:state.js
##內容:const state = { singer:{}#}export default state 6 .功能:入口檔:index.js##內容:
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)
// 開發環境時,追蹤每次state的修改
const debug = process.env.NODE_ENV !== 'production'
export default new Vuex.Store({
actions,
getters,
mutations,
state,
strict: debug,
plugin: debug ? [createLogger()] : []
})
#
以上是實作vuex的初始化方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!