Axios 使用说明

get请求

1 on_sum: function () {
2     axios.get('http://127.0.0.1:8000/test/'
3     ).then(response=>{
4         alert('ok')
5     }).catch(error=>{
6         alert(error)
7     })
8 }

post请求

 1 on_sum: function () {
 2     axios.post('http://127.0.0.1:8000/test/',
 3         {'key':'value'
 4       ......
 5         }).then(response=>{
 6 
 7     }).catch(error=>{
 8 
 9     })
10 }

axios API


on_sum: function (){
axios({
method:'post',
url:'/test/',
data:{
firstName: 'Fred',
lastName: 'Flintstone'
}
}).then(response=>{
  pass
}).error(error=>{
      pass
})
},

请求方法的别名

为方便起见,为所有支持的请求方法提供了别名

  1. axios.request(config)
  2. axios.get(url[, config])
  3. axios.delete(url[, config])
  4. axios.head(url[, config])
  5. axios.post(url[, data[, config]])
  6. axios.put(url[, data[, config]])
  7. axios.patch(url[, data[, config]])
原文地址:https://www.cnblogs.com/lvye001/p/9968737.html