实现vuex的初始化方法
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的初始化方法的详细内容,更多请关注其它相关文章!
上一篇: Linux安装过程中编译PHP时报错
下一篇: 实现瀑布流布局的俩种方法