方法一:
在mian.js中寫入函數:
Vue.prototype.bb = function () {
alert('OK');
}
然后在任何組件中都可以調用:
this.bb()
方法二:
先在skyworth-global.js中添加函數:
exports.install = function (Vue, options) {
Vue.prototype.bb = function (){
alert('OK');
};
};
然后在main.js中引入:
import * as skyGlobal from '../static/js/skyworth-global';
Vue.use(skyGlobal)
然后就可以在任何組件中調用:
this.bb()
若有不正確的地方歡迎指出,希望本文對你有幫助