遇到一个非常非常奇怪的问题
uniapp的跨域问题。没想到21世纪了居然有这么离谱的东西存在。
前端uniapp端口用本地的8080
后端端口用本地的8088
下面的代码在我vue项目里都是没有问题的,反而在uniapp里出了笑话,有人跟我说是这两个页面的代码冲突了
baseURL设为“”就行,很可惜不行。
好了话不多说直接上代码:跨域设置
"h5" : {
"devServer" : {
"port" : 8080,
"disableHostCheck": true,
"https" : false,
"proxy" : {
"/api" : {
"target" : "http://192.168.18.43:8088",
"changeOrigin" : true,
"secure" : false,
"pathRewrite" : {
"^/api" : ""
}
}
}
},
"title" : "抽奖信息采集",
"router" : {
"mode" : "hash"
}
}
还有就是我的axios设置https.js
import axios from "axios";
// 创建自定义接口服务实例
const http = axios.create({
baseURL: 'http://192.168.18.43:8088',//根据个人后端情况,修改此处baseURL
timeout: 6000, // 不可超过 manifest.json 中配置 networkTimeout的超时时间
withCredentials: true,
headers: {
'Content-Type': 'application/json',
//'X-Requested-With': 'XMLHttpRequest',
},
})
// 拦截器 在请求之前拦截 添加token
http.interceptors.request.use(config => {
//请求前有关处理逻辑
return config
})
// 响应后的拦截
http.interceptors.response.use(response => {
//响应拦截处理逻辑
return response;
}, error => {
return Promise.reject(error.message)
})
export default http