get:获取数据
axios.get('/data.json',{
params: {
id: 12
}
}).then((res)=>{
console.log(res)
})
axios({
method: 'get',
url: '/data.json',
params: {
id: 12
}
}).then(res=>{
console.log(res)
})
post:提交数据(表单提交、文件上传)
application/json方式提交
let data = {id:12}
axios.post('/post',data).then((res)=>{
console.log(res)
})
axios({
method: 'post',
url: '/post',
data: data
}).then(res=>{
console.log(res)
})
form-data表单提交 图片上传,文件上传
let formData = new FormData()
for(let key in data) {
formData.append(key,data[key])
}
axios.post('/post',formData).then((res)=>{
console.log(res)
})
axios({
method: 'post',
url: '/post',
data: formData
}).then(res=>{
console.log(res)
})
put:更新数据(所有数据推送到后端)
axios.put('/put',data).then((res)=>{
console.log(res)
})
axios({
method: 'put',
url: '/put',
data: data
}).then(res=>{
console.log(res)
})
patch:更新数据(只将修改的数据推送到后端)
axios.patch('/patch',data).then((res)=>{
console.log(res)
})
axios({
method: 'patch',
url: '/patch',
data: data
}).then(res=>{
console.log(res)
})
delete:删除数据
axios.delete('/delete',{
params: {
id: 12
}
}).then((res)=>{
console.log(res)
})
axios.delete('/delete',{
data: {
id: 12
}
}).then((res)=>{
console.log(res)
})
axios({
method: 'delete',
url: '/delete',
params: data
}).then(res=>{
console.log(res)
})
axios({
method: 'delete',
url: '/delete',
data: data
}).then(res=>{
console.log(res)
})
查看:解决axios @0.20.0版本delete方法遇到的问题