Vuex 构建笔记(一)
getters相当于取出状态后的过滤器
mutations类似于事件外部提交触发回调
Action 提交的是 mutation
{
methods: mapActions() // 如果没有其它组件内的定义的方法,可以这样写
}
{
methods: {
...mapActions(),// 如果有其他定义的方法
otherMethod1 () {},
otherMethod2 () {}
}
}
解决...mapActions 使用报错问题
npm install --save-dev babel-preset-es2015
在package.js里面增加"babel-preset-stage-2": "^6.1.18",
然后npm i 安装依赖
接下来在.babelrc 配置
{
"presets": [
["es2015", { "modules": false }]
],
"plugins": ["transform-object-rest-spread"]
}
component->actions->mutations->state->getters->component