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

 1 on_sum: function () {
 2     axios({
 3         methods:'post',
 4         url:'/test/',
 5         data:{
 6             firstName: 'Fred',
 7             lastName: 'Flintstone'
 8         }.then(response=>{
 9             pass
10         }).catch(error=>{
11             pass
12         })
13     })
14 }

请求方法的别名

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

  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]])

猜你喜欢

转载自www.cnblogs.com/lvye001/p/9968737.html