方法一Vue.prototype:
main.js加入
Vue.prototype.方法名 = { 功能 } 直接在Vue构造函数中添加此方法,后续可以所有组件调用this.internalFolding(folding)
//Vue 全局挂载自定义函数
//folding为传进来的参数
//internalFolding 为函数名
Vue.prototype.internalFolding = function (folding){
//函数内容
}
方法二:写好自己需要用得公共文件
main.js加入公用文件
import folding from '../static/js/folding' // 方法名和导入得公用文件路径
Vue.use(folding);
后续所有组件可以调用 this.internalFolding(this.folding)