精简地说下vue的mixin(混合)策略
vue混合策略简说:
var mixin = {
methods: {
foo: function () {
console.log('foo')
},
conflicting: function () {
console.log('from mixin')
}
},
created() {
this.conflicting()
}
}
var vm = new Vue({
el: '#app',
mixins: [mixin],
methods: {
bar: function () {
console.log('bar')
},
conflicting: function () {
console.log('from self')
}
},
created() {
this.conflicting()
}
})
vm.foo()
vm.bar()
vm.conflicting()
//执行结果?
//混合策略?
1 回复
vue mixin 混合策略 同名的函数,实例对象的会覆盖mixin的 函数