一、设置
main.js
// 1.引入 import * as API from '@/api'; new Vue({ render: h => h(App), beforeCreate() { Vue.prototype.$bus = this // 2.原型 Vue.prototype.$API = API }, // 注册路由 router, // 注册Vuex store }).$mount('#app')
二、使用
this.$API.函数