如何将Axios代码转换为jwt Token获取api



我正在尝试将axios的简单语句转换为fetch我在教程中见过这段代码,但在axios

中不可行
const { data } = await axios.post('http://localhost:5000/login', { email })

我已经尝试过下面的代码

const { data } = await fetch('http://localhost:5000/login', { email })

但是它给我404错误

Fetch的API水平较axios低。你需要再啰嗦一些。除非您正在发送GET请求,否则您需要显式地指定方法:

fetch('http://localhost:5000/login', {
method: 'POST',
headers: {
// some headers of your need, e.g.:
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify({ email })
})

const { data } = await fetch('http://localhost:5000/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email })
})

最新更新