简单记录一下axios get请求,使用formData传递参数给后台
// GET 请求传递 formData
// get 请求传递formData
const formData = new FormData()
formData.append('name','admin')
const params = new URLSearchParams(formData)
// 链接地址 /api/user/login?name=admin
axios.get(`/api/user/login?${params.toString()}`,
headers:{
'Content-Type':'application/x-www-form-urlencoded'
})
.then (res= => {
console. log (res)
})
POST 请求传递 formData
// post 请求传递formData
const formData = new FormData()
formData.append('name','admin')
axios.post('/api/user/login',formData)
.then (res= => {
console. log (res)
})