项目场景:
在开发中难免会遇到出现跨域问题,有时候后台小友可能各种原因没处理,这时候我们前端也可以自行处理,接口跨域就是浏览器的同源策略限制,当一个请求url的协议、域名、端口三者之间任意一个与当前页面url不同即为跨域;
解决方案:
来个可以复制粘贴的manifest.json!!
"h5" : {
"router" : {
"mode" : "history",
"base" : "./"
},
"template" : "",
"title" : "sqzy-h5-boss",
"devServer" : {
"port" : 8080, //端口号
"disableHostCheck" : true,
"proxy" : {
"/api" : {
"target" : "http://192.168.1.157:8081", //目标接口域名
"changeOrigin" : true, //是否跨域
"secure" : false, // 设置支持https协议的代理
"pathRewrite": {
"^/api": "/"
}
}
}
}
}
然后在你调接口的页面:
getThressSalesVolume(){
that.$request({
url: '/api/xxxxxxxx' //接口地址
}).then((res) => {
if (res.code == 0) {
console.log(res.data)
}
})
},
So easy!!^-^ ~