使用了axios
1. 在axios中
在 vite.config.js 中
target是接口域名,这里假如 target: 'http://www.baidu.com'
两张图的红框位置保持一致
在.vue中
2.开发环境
npm run dev产生的地址比如说是http://localhost:3000
那么 在vue中访问接口 'shiyananpai/detail' 在network显示 http://localhost:3000/apia/shiyananpai/detail
实际上访问的是 http://www.baidu.com/api/shiyananpai/detail
3. 生产环境
num run build 产生了dist
经过一上午的百度,我猜测dist中可能并不包含vite.config.js中的配置。
所以代理需要到放置dist的服务器配置
如果dist所在服务器为apache
ProxyRequests Off
<Proxy /apia>
Order deny,allow
Allow from all
</Proxy>
#反向代理配置
ProxyPass /apia http://xm.com/index.php/api
ProxyPassReverse /apia http://xm.com/index.php/api