我正在尝试在Vue页面中映射商店的状态变量:
<script>
export default {
data: () => ({
localData: []
}),
computed: {
someLocalProperty: {
get: function () {
// ....
}
},
...mapState({
one: state => state.one,
two: state => state.two,
three: state => state.three,
})
},
};
</script>
但是,这给了我以下错误:
Uncaught Error: Module build failed:
71 : data: () => ({
72 : localData: []
73 :
74 : }),
75 : computed: {
Object spread operator requires specified objectAssign option with 'Object.assign' or polyfill helper. (75:14)
我究竟做错了什么?
我曾尝试将
objectAssign: 'Object.assign'
添加到我的webpack配置中,但这无济于事:rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
objectAssign: 'Object.assign',
preLoaders: {
i18n: 'yaml-loader'
},
loaders: {
i18n: '@kazupon/vue-i18n-loader'
}
}
},
{
test: /\.js$/,
loader: 'buble-loader',
exclude: /node_modules/,
options: {
objectAssign: 'Object.assign'
}
},
{
test: /\.styl$/,
loader: ['style-loader', 'css-loader', 'stylus-loader']
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: 'file-loader?name=public/fonts/[name].[ext]'
}
]
},
最佳答案
也许您的buble-loader配置错误?
从original project documentation中查看以下片段:
module: {
loaders: [
{
test: /.js$/,
loaders: 'buble',
include: path.join(__dirname, 'src'),
query: {
objectAssign: 'Object.assign'
}
}
]
}