vuejs - mixin的基本用法
访问量: 1903
官方文档:https://cn.vuejs.org/v2/guide/mixins.html
1. 使用方式:
my_mixin = { created: function(){ console.info(" hi from mixin"); }, methods: { hello: function(){ console.info("hello from mixin"); } } var Component = Vue.extend({ mixins: [my_mixin] }) var my_component = new Component() // hi from mixin
2. 对于mixin中的同名函数:
如果属于钩子方法(created ... ) 该函数会执行。 而且是先执行
如果不属于钩子方法,该函数不会被执行。