1、在utils文件夹中新建utils.js

/**
 * 通用js方法封装处理两种方式
 * Copyright (c) 2019 ruoyi
 */
 
/** 第一种方式*/
function myFun() {
    console.log('this is my function')
}
function fn1(){
  console.log("全局方法一")
}
 
// 将上面连个全局公共方法,组合成一个对象,并暴露出去
export default {
    myfun,
    fn1
}    
 
/** 第二种方式*/
export function myFun() {
    console.log('this is my function')
}
export function fn1() {
    console.log("全局方法一")
}

2、配置引用

2.1.1、全局调用:在main.js 进行配置

/** 第一种挂载方式:*/
 
import myfun from './utils/utils/myFun'
import fn1 from './utils/utils/fn1'
 
Vue.prototype.myfun = myfun;
Vue.prototype.fn1= fn1;
 
/** 第二种挂载方式:*/
import utils from './utils/utils'
Vue.prototype.commonApi = utils;

2.1.2 、页面中引用

text(){
    this.fn1();// 使用fn1方法
    this.myfun() // 使用myfun方法
}


text(){
    this.commonApi.fn1();// 使用fn1方法
    this.commonApi.myfun() // 使用myfun方法
}

2.2 局部调用:在页面中引入

import { myFun}  from 'path'
// 使用
myFun()    //注意这里不加 this