vue2与vue3中全局配置axios的不同点

Vue3

import {createApp} from 'vue'
import App from './App.vue'
//1.导入axios
import axios from 'axios'
const app = create(App)
//2.配置请求根路径
axios.defaults.baseURL = 'http://www.www.cn'
//3.全局配置axios
app.config.globalProperties.$http = axios
app.mount('#app')

Vue2

import Vue from 'vue'
import App from './App.vue'
//1.导入axios
import axios from 'axios'
const app = create(App)
//2.配置请求根路径
axios.defaults.baseURL = 'http://www.www.cn'
//3.通过Vue构造函数的原型对象,全局配置axios
Vue.prototype.$http = axios
new Vue({
render:h=>h(App),
}).monut('#app')
posted @ 2021-11-15 17:14  ajaXJson  阅读(270)  评论(0编辑  收藏  举报