vue mixins & extends

1.

const myMixin = {
created(){
console. log( this. msg + '1')
},
methods:{
hello(){
console. log( this. msg + '2')
}
}
};
Vue. mixin({
created(){
console. log( this. msg + '3');
},
methods:{
hello(){
console. log( this. msg + '4');
}
}
})
//-----------------------------------------------------------
//如果全局mixin和组件内mixin有同名的钩子函数,钩子函数都会执行,并且先执行全局后执行组件内。
//hello3 index.html:30
//hello1 index.html:20
//-----------------------------------------------------------
Vue. filter( 'uppercase', function( value){
return value. toUpperCase();
})
var vm = new Vue({
el: "#app",
mixins:[ myMixin],
data:{
msg: 'hello'
}
});

2.

const myMixin = {
created(){
this. hello();
},
methods:{
hello(){
console. log( this. msg + '2')
}
}
};
Vue. mixin({
created(){
this. hello();
},
methods:{
hello(){
console. log( this. msg + '4');
}
}
})
//-----------------------------------------------------------
// 组件内的会覆盖全局的。
//hello2 index.html:24
//hello2 index.html:24
//-----------------------------------------------------------

3.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值