Reactjs 如何从正面点击Express后端?
我在heroku上部署了我的react+express应用程序,似乎无法访问server.js中提供的登录api 这是前端,它在本地工作,甚至在几天前工作过,但它突然停止了Reactjs 如何从正面点击Express后端?,reactjs,express,heroku,Reactjs,Express,Heroku,我在heroku上部署了我的react+express应用程序,似乎无法访问server.js中提供的登录api 这是前端,它在本地工作,甚至在几天前工作过,但它突然停止了 <a href="/login"> <Button className="app-button" variant="success" size="lg" style={{marginT
<a href="/login">
<Button className="app-button" variant="success" size="lg" style={{marginTop:10, color: 'black'}}>
Log In
</Button>{' '}
</a>
使用fetch/axios尝试并点击它也不起作用React在客户端有路由,因此
a
标记将不起任何作用
您需要像fetch或axios这样的库来启动指向运行express server的url的post
to/login
import axios from 'axios';
const login = async () => {
const response = await axios.post('http://localhost/login');
// do something with response
}
return {
<Button onClick={() => login()}>
Log In
</Button>
}
从“axios”导入axios;
const login=async()=>{
const response=等待axios.post('http://localhost/login');
//做些有反应的事情
}
返回{
登录()}>
登录
}
import axios from 'axios';
const login = async () => {
const response = await axios.post('http://localhost/login');
// do something with response
}
return {
<Button onClick={() => login()}>
Log In
</Button>
}