1. prototype
Vue.prototype.testFn = function(){
console.log("test")
}
2. mixin
Vue.mixin({
created: function () {
console.log("test")
}
})
3.$root
// 创建全局方法
this.$root.$on('test', function(){
console.log('test');
})
// 销毁全局方法
this.$root.$off('test');
// 调用全局方法
this.$root.$emit('test');
网友评论