submitForm = (e) => {
e.preventDefault();
sessionStorage.setItem('username', this.state.username);
sessionStorage.setItem('password', this.state.password);
axios.post('/authenticate', {data: {
username: sessionStorage.getItem('username'),
password: sessionStorage.getItem('password')
}})
.then((response) => {
this.setState({
jwttoken: response.data
})
},
sessionStorage.setItem('token', this.state.jwttoken)
)
这是我的发帖请求,但似乎不起作用 我需要在正文中添加用户名和密码, 我做对了吗?
答案 0 :(得分:1)
您可以尝试;
const url = Your url
const { username, password } = this.state
const data = {
username,
password
}
axios.post(url, data)
...