import {getTodos} from '../store/actions'
import {mapState, mapActions} from 'vuex'
export default{
name: 'VuexDemo',
data(){
return {
msg: 'VuexDemo'
}
},
computed: mapState({
count: state => state.todo.length
}),
methods: {
...mapActions(['getTodos'])
},
created(){
this.getTodos()
console.log(this.count)
}
}
然后就报错了。。...是非法字符。。
Module build failed: SyntaxError: D:/01workspace/GitHub/mint-demo/src/components/Vuexdemo.vue: Unexpected token (30:8)
28 | }),
29 | methods: {
> 30 | ...mapActions(['getTodos'])
| ^
31 | },
32 | created(){
33 | this.getTodos()
package.json 部分
"babel-core": "^6.0.0",
"babel-loader": "^6.0.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.0.0",
"babel-preset-stage-3": "^6.17.0",
"babel-runtime": "^6.20.0"
.babelrc
{
"presets": [
[
"es2015",
"stage-3"
]
],
"plugins": [
"transform-runtime"
]
}
是不是 babel 的配置有问题,只用 stage-3 试试。