base.js文件,文件位置可以放在跟main.js同一级,方便引用

exports.install = function (Vue, options) {
   Vue.prototype.text1 = function (){//全局函数1
    alert('执行成功1');
    };
    Vue.prototype.text2 = function (){//全局函数2
    alert('执行成功2');
    };
};

main.js入口文件:

import base from './base'//引用
Vue.use(base);//将全局函数当做插件来进行注册

组件里面调用:

this.text1();
this.text2();

相关文章:

  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2021-04-19
  • 2021-09-29
  • 2022-12-23
  • 2021-04-30
  • 2022-12-23
猜你喜欢
  • 2021-11-28
  • 2021-10-20
  • 2021-10-20
  • 2021-11-28
  • 2021-11-16
相关资源
相似解决方案