如何将反应状态传递给Node后端?

时间:2020-07-29 21:53:26

标签: node.js reactjs

我正在尝试使用Node + React构建一个天气应用程序。使用以下代码在Node中获取天气API:

const apiUrl = `http://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=${process.env.REACT_APP_WEATHER_API_KEY};
axios.get(apiUrl)
    .then(response => { res.json(response.data) })
    .catch(error => {
        res.redirect('/error');
        console.log(error);
    });

您可以看到latitudelongitude是变量。现在,我已经从用户输入中获取了我的React应用程序中的地理坐标,并存储在以下状态:

this.setState({
    coordinate: [response.result.latitude, response.result.longitude];
});

问题是,如何将状态传递给我的Node代码,以便lat=${latitude}&lon=${longitude}可以接收地理坐标?

0 个答案:

没有答案