0
我第一次使用redux thunk
。链接操作的正确方式是什么?在redux thunk中链接操作的正确方法?
我想获取用户输入后给出的位置,当有响应数据从Google Maps API
,那么我想立即使用该数据来获取该位置的天气。 Redux thunk
正在工作,但仅用于第一次操作(取回位置)。 Data2
在request2
总是undefined
,你能告诉我这是为什么吗?
export function fetchLocation(city) {
const urlGoogle = `https://maps.googleapis.com/maps/api/geocode/json?address=${city}&key=${API_KEY_GOOGLE}`;
const request = axios.get(urlGoogle);
return (dispatch) => {
request.then(({ data }) => {
dispatch({ type: FETCH_LOCATION, payload: data });
const lat = data.results["0"].geometry.location.lat;
const lng = data.results["0"].geometry.location.lng;
const urlWunder = `https://api.wunderground.com/api/${API_KEY_WUNDERGROUND}/forecast10day/q/${lat},${lng}.json`;
console.log(urlWunder); // Link is ok, it works in browser
const request2 = axios.get(urlWunder);
request2.then(({ data2 }) => {
console.log('Data2', data2); // Getting undefined, why ?
dispatch({ type: FETCH_WEATHER, payload: data2 });
});
});
};
}
非常感谢你@markerikson! –