我正在使用 mixin 来添加和覆盖 vue 数据。我可以添加新数据,但似乎无法覆盖现有数据。这是简单的代码:
var mixin = {
data: function() {
return {
foo: 'boo',
test: 'blah'
}
}
}
var vm = new Vue({
el: '#vue-instance',
mixins: [mixin],
data: function() {
return {
foo: 'bar'
}
}
});
当我运行它时,“test”正确地等于“blah”,但“foo”仍然等于“bar”。除了添加新数据之外,是否还可以使用 mixin 覆盖现有的 vue 数据?
这是一个 fiddle :
最佳答案
Options that expect object values ... will be merged into the same object. The component’s options will take priority when there are conflicting keys in these objects
(强调我的)。
如果您想要不同的合并策略,you can define one .
关于javascript - 覆盖vue中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42304671/