Axios常用得请求方法
- get:一般用户获取数据
- post:一般用于表单提交与文件上传
- patch:更新数据(只将修改得数据推送到后端)
- put:更新数据(所有数据推送到服务器)
- delete:删除数据
下面主要举get post 使用的例子
axios.get('url',{})
axios.get('http://localhost:8000/del_tool',{
params:{
tool_id:tool_id
}
}).then(res=>{
this.tool_list = res.data.tools
})
axios('url')
axios('http://localhost:8000/get_tools/').then(res=>{
this.tool_list = res.data.tools
console.log(this.tool_list)
})
axios.post('url',{})
axios.post('http://localhost:8000/save_tool/',this.form_data).then(res=>{
this.dialogVisable = false;
this.tool_list = res.data
})
axios({ url:xxx,method:xxx,data:xxx })
axios({
url: '/api/user/login' ,
method: 'post',
headers: {
'Content-Type': 'application/json'
},
data:{
username: this.user,
pwd: this.pwd
}
}).then((res) => {
console.log(res)
})
axios({
url: '/api/user/login' ,
method: 'post',
headers: {
'Content-Type': 'application/json'
},
params:{
username: this.user,
pwd: this.pwd
}
}).then((res) => {
console.log(res)
})