vue代理
1、manifest.json {}增加代理配置
和"name" : "demo01"平级
配置是/api的不需要配置pathRewrite
"h5" : {
"devServer" : {
"disableHostCheck" : true,
"proxy" : {
"/shoucheng" : {
"target" : "http://i.shouchengholdings.cn:59113", //请求的目标域名
"changeOrigin" : true,
"secure" : false,
"pathRewrite" : {
"^/shoucheng" : "/"
}
},
"/api": {
"target": "http://i.shouchengholdings.cn:59113", //请求的目标域名
"changeOrigin": true,
"secure": false
//配置是/api的不需要配置pathRewrite
// "pathRewrite": {
// "^/api": "/api/api"
// }
}
},
"port" : 8848,
"https" : false
},
"router" : {
"mode" : "hash",
"base" : "/platform/runtime/epp/h5/"
},
"domain" : "http://i.shouchengholdings.cn",
"title" : "通知公告"
}
2 、配置完manifest.json重启服务
3、通过代理获取数据
info.vue文件
<script>
export default {
methods: {
getList() {
uni.request({
//把代理的路径加上/shoucheng
url: "/shoucheng/api/cms/cs/v1.0/columncontent/common/query",
//api的写法
//url: "/api/cms/cs/v1.0/columncontent/common/query",
//type : "post",
//type : "GET"没问题,type : "post"会报错
method: 'POST',
data: param,
header: {
"Content-Type": "application/json",
},
crossDomain: true,
success: res => {
console.log(res);
this.dataList = res["data"]["data"];
this.isLoading = false;
},
fail: () => {},
complete: () => {}
});
}
}
}
</script>
注意事项:
1、使用代理获取的数据,文字可以正常显示,图片可能不显示,放到服务器上就可以正常显示
2、打包之前需要把接口上的代理去掉,不去掉代理的路径在服务器上获取不到数据