在main.ts中代码:
import axios from 'axios'
app.config.globalProperties.$http = axios
在普通页面去调用$http
//获取当前组件的实例、上下文来操作router和vuex等
import { getCurrentInstance } from 'vue'
setup(){
const { ctx } = getCurrentInstance() as any
console.log('ctx', ctx, ctx._)
const { $http } = ctx._.appContext.config.globalProperties //全局参数在这一层
$http.get('/api').then((res: any) => {
console.log(res)
})
}
直接看其他人都是直接调用$http的得到的是underfind 后面才发现在这一层ctx._.appContext.config.globalProperties