你究竟是如何使用 mapState 的?
How exactly do you use mapState?
我正在尝试在 Vuex 中使用 mapState,如下所示:
mapState({
locations: state => state.locations,
types: state => state.models.types,
models: state => state.models.models,
vendors: state => state.models.vendors,
statuses: state => state.statuses,
})
我收到 'Unexpected Token' 编译错误,Browserify 指向第一个粗箭头。如果我尝试使用传播运算符:
...mapState({
编译错误发生在...
您似乎没有安装 babel。 Babel 是 JavaScript 的转译器,它将 ES6 转换为今天在我们的浏览器中运行的代码。
您将需要babelify in your setup of Browserify. you can go through any tutorial了解如何使用 browerify 设置 babel,有很多可用的。
那是一个object property spread。目前几乎没有任何东西原生支持它,es2015 babel 预设也不包含它。
用npm i -D babel-plugin-transform-object-rest-spread
安装
将其添加到您的 .babelrc。它应该看起来像这样:
{
"presets": ["es2015"],
"plugins": ["transform-object-rest-spread"]
}
我正在尝试在 Vuex 中使用 mapState,如下所示:
mapState({
locations: state => state.locations,
types: state => state.models.types,
models: state => state.models.models,
vendors: state => state.models.vendors,
statuses: state => state.statuses,
})
我收到 'Unexpected Token' 编译错误,Browserify 指向第一个粗箭头。如果我尝试使用传播运算符:
...mapState({
编译错误发生在...
您似乎没有安装 babel。 Babel 是 JavaScript 的转译器,它将 ES6 转换为今天在我们的浏览器中运行的代码。
您将需要babelify in your setup of Browserify. you can go through any tutorial了解如何使用 browerify 设置 babel,有很多可用的。
那是一个object property spread。目前几乎没有任何东西原生支持它,es2015 babel 预设也不包含它。
用
npm i -D babel-plugin-transform-object-rest-spread
安装
将其添加到您的 .babelrc。它应该看起来像这样:
{ "presets": ["es2015"], "plugins": ["transform-object-rest-spread"] }