1.利用js中的原型prototype给Vue创建全局的方法这样在任何组件里面也都可以使用了,缺点是调用这个方法的时候没有提示

Vue.prototype.method = method

2.通过mixin来分发 Vue 组件中的可复用功能,这个方法很灵活,当组件的方法同名时,会恰当的进行合并,如果产生冲突,以组件的数据优先
官方文档:https://cn.vuejs.org/v2/guide/mixins.html

Vue.mixin({
    methods...
})
new Vue({
    store,
    router,
    render: h => h(App),
}).$mount('#app')
Last modification:September 27, 2019
If you think my article is useful to you, please feel free to appreciate