// 定义一个混合对象
var myMixin = {
created: function () {
this.hello()
},
methods: {
hello: function () {
console.log('hello from mixin!')
}
}
}
// 定义一个使用混合对象的组件
var Component = Vue.extend({
mixins: [myMixin]
})
var component = new Component()
//混合钩子
var lifemixin = {
created(){
//限执行
console.log('mixin created!');
}
}
new Vue({
created(){
//后执行
console.log('vue created!');
},
mixins:[lifemixin]
})
//merge mixins
var merge = {
methods:{
foo(){
console.log('mixin foo!');
},
conflict(){
console.log('mixin conflict!');
}
}
}
var vm =new Vue({
mixins:[merge],
methods:{
bar(){
console.log('bar');
},
conflict(){
console.log('from vue !');
}
}
})
vm.foo();
vm.bar();
vm.conflict();
console