1.修改config -> index.js文件
proxyTable: {
“/api”: {
target: “http://localhost:3000”,
changeOrigin: true,
pathRewrite: {
‘^/api’: ‘’
}
}
}
2. 在main.js中添加host
Vue.prototype.HOST = ‘/api’
3. 在post 或 get 请求方法中的请求接口url写为 this.HOST+ “接口地址” (注:访问时需要把全局设置的公共接口路径注释掉)
注意:此种跨域解决方案,只能适用于测试阶段,打包的时候不会具备服务器,不能跨域了,后端解决。
VUE跨域解决方案
最新推荐文章于 2024-07-24 13:30:37 发布