A Vue.js project
# install dependencies
npm install
# serve with hot reload at localhost:8080
npm run dev
# build for production with minification
npm run build
# build for production and view the bundle analyzer report
npm run build --report
For a detailed explanation on how things work, check out the guide and docs for vue-loader.
- 安装vuex,建vuex的目录结构---见文件夹store
- 将vuex引入项目 ----见main.js
- 在store-index.js内注入vuex的内容
- 在state内初始化变量
- getter相当于vue中的计算属性,将变量缓存起来,只有依赖的值发生变化时才会触发(使用辅助函数调用的方法可能会报错,解决方法见app.vue调用处)
- 数据的实际在mutation中修改,mutation的回调函数会接受state和要修改的值。