vue.config.js文件里module.exports = {devServer: {proxy: {//配置跨域/api: {target: http://localhost:18080/, //这里后台的地址模拟的;应该填写你们真实的后台接口changOrigin: true, //允许跨域pathRewrit...

vue.config.js文件里
module.exports = {
devServer: {
proxy: {
//配置跨域
"/api": {
target: "http://localhost:18080/", //这里后台的地址模拟的;应该填写你们真实的后台接口
changOrigin: true, //允许跨域
pathRewrite: {
/**
*重写路径,当我们在浏览器中看到请求的地址为:http://localhost:8888/api/...... 时
*实际上访问的地址是:http://localhost:18080/......,因为重写了 /api
*/
"^/api": "",
},
},
},
},
};
附vue.config.js
织梦狗教程
本文标题为:vue解决跨域问题


基础教程推荐
猜你喜欢
- JavaScript垃圾回收机制(引用计数,标记清除,性能优 2022-08-31
- 在IE中为abbr标签加样式 2022-10-16
- Ajax提交表单并接收json实例代码 2023-02-13
- ajax实现数据分页查询 2023-01-31
- 纯javascript的ajax实现php异步提交表单的简单实例 2022-12-28
- Unicode中的常用字母小结 2022-09-21
- 关于ajax异步访问数据的问题 2023-02-23
- 解决:layUI数据表格+简单查询 2022-12-16
- 原生ajax瀑布流demo分享(必看篇) 2023-02-01
- AJax 把拿到的后台数据在页面中渲染的实例 2023-02-22