1、新建js,导出您的方法:
var func = { msg(){ alert(111) } } export default func;2、在main.js全局引入
import { createApp } from 'vue' import App from './App.vue' //引入 import axios from 'axios' import func from './assets/js/func' var app = createApp(App) //注入 app.config.globalProperties.axios = axios; app.config.globalProperties.func = func; app.mount('#app')3、使用方法:
this.func.msg(); this.axios.get('',{ }).then((res) => { console.log(res) })