vuex入门的详细使用步骤
安装
在webstrom中通过指令
npm install vuex --save
进行安装。注意==–save==必须加上,否则不会自动保存
编写index.js
在src文件夹下创建文件夹:store,在文件夹下创建:index.js
在index中导入Vue/Vuex,安装Vuex插件,创建Vuex对象并导出
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store=new Vuex.Store({
})
export default store
在store中添加state属性,在state中添加一个数,添加mutations属性,在mutations中添加两个方法