gpt4 book ai didi

javascript - 如何使用对象传播/mapState 助手

转载 作者:行者123 更新时间:2023-12-04 00:08:44 28 4
gpt4 key购买 nike

我正在尝试在我的 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'
}
}
]
}

关于javascript - 如何使用对象传播/mapState 助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47030779/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com