vue3 使用axios有三种方法
1、局部使用,import axios from “@/api/axios/http.js”;直接使用 axios
2、全局使用:
先在main.js中 :app.config.globalProperties.$http = axios // 将axios注入到Vue应用程序的原型上
*方式一:*在页面
import { getCurrentInstance } from "vue";
const { proxy, ctx } = getCurrentInstance();
用proxy.$http.get() 使用;
*方式二:*在页面
import { getCurrentInstance } from "vue";
const currentInstance = getCurrentInstance();
const { $http, $message, $route } = currentInstance.appContext.config.globalProperties;
用$http.get() 使用;
引用时注意大小写问题