如何在vue-manage-system后台管理模板中的mian.js添加全局axios?

如何在vue-manage-system后台管理模板中的mian.js添加全局axios?

mian.js文件内容

import {createApp} from 'vue'

import App from './App.vue'

import router from './router'

import store from './store'

import installElementPlus from './plugins/element'

import './assets/css/icon.css'

const app = createApp(App)

installElementPlus(app)

app

.use(store)

.use(router)

.mount('#app')


回答:

vue2

import axios from 'axios'

Vue.prototype.$axios = axios

使用this.$axios.xxx

vue3global-api

Vue.prototype Replaced by config.globalProperties
import axios from 'axios';

const app = Vue.createApp(App);

app.config.globalProperties.$axios = axios;

使用this.$axios.xxx

vue3provide/inject

Provide

import axios from 'axios';

const app = Vue.createApp(App);

app.provide('$axios', axios);

Inject

Composition API:

const { inject } = Vue;

...

setup() {

const $axios = inject('$axios');

// $axios.get(...)

}

Options API:

inject: ['$axios'],

以上是 如何在vue-manage-system后台管理模板中的mian.js添加全局axios? 的全部内容, 来源链接: utcz.com/p/935471.html

回到顶部