vue-cli+springboot部署到linux中tomcat和nginx中时ajax请求返回200 ok(来自磁盘缓存),但是取不到数据。
vue代码
getIpAddress(){
axios.get("http://ip-api.com/json?lang=zh-CN").then(ipAddress=>{
return ipAddress;
}).then(ipAddress => {
let apiKey="*************************";
axios.get("/juhe/ip/ipNewV3?ip="+ipAddress.query+"&key="+apiKey).then(location=>{
this.location=location;
}).then(() => {
let apiKey="*********************************";
axios.get("/juhe/simpleWeather/query?city="+this.location.result.City+"&key="+apiKey).then(resp=>{
this.weather=resp.result;
});
})
})
}
nginx配置
location /juhe {
add_header Cache-Control no-store,no-cache,must-revalidate;
proxy_pass https://apis.juhe.cn;
rewrite ^/juhe /;
}
查找原因是nginx做正向代理配置有问题
清下缓存 看有没有返还数据
本地测试有没有问题 不见得是部署问题
排查一下
先打印下this.location这个值是什么
无法读取未定义的属性City和Province
你这个 值 做个非空判断
if(obj.City){
// 再使用
}