创建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()] : []
})
立即学习“前端免费学习笔记(深入)”;