//在vite.config。js中,同插件配置同級進行配置server:{proxy:{"/myrequest":{//代理域名,可自行修改target:"https://m.wzj.com/",//訪問服務器的目標域名changeOrigin:true,//允許跨域configure:(proxy,options) => {proxy.on("proxyReq",(proxyReq,req,res) => {proxyReq.setHeader("Referer","https://m.wzj.com/mall");//設置訪問服務器的目標請求頭}); },rewrite:(path)=>path.replace(/^\/myrequest/,"")//替換代理域名為""},},},
2.在發請求的位置使用自己配置的代理服務器的域名進行訪問
import axios from "axios";
// https://m.wzj.com/proxy/articles/featured/list?limit=100&offset=0
export const homeData=()=>{let url='myrequest/proxy/articles/featured/list?limit=10&offset=0'axios.get(url).then((result)=>{return result})
}