码迷,mamicode.com
首页 > 移动开发 > 详细

vue中axios安装及使用

时间:2019-11-04 15:46:01      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:from   cti   com   npm   pos   row   set   ofo   send   

axios  基于HTTP客户端的浏览器和node.js

网址链接:https://github.com/axios/axios

 

 

1、特征:

  • 制作,使XMLHttpRequest从浏览器
  • 制作,使http来自node.js的请求
  • 支持承诺API
  • 拦截请求和响应
  • 转换请求和响应数据
  • 取消请求
  • JSON数据的自动转换
  • 客户端支持防止XSRF

 

 

2、安装:

Using npm:
$ npm install axios
Using bower:
$ bower install axios
Using yarn:
$ yarn add axios
Using cdn:
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

 

 

3、配置使用:

post方法:
// Send a POST request
axios({
  method: ‘post‘,
  url: ‘/user/12345‘,
  data: {
    firstName: ‘Fred‘,
    lastName: ‘Flintstone‘
  }
});



get方法:
// GET request for remote image
axios({
  method: ‘get‘,
  url: ‘http://bit.ly/2mTM3nY‘,
  responseType: ‘stream‘
})
  .then(function (response) {
    response.data.pipe(fs.createWriteStream(‘ada_lovelace.jpg‘))
  });

 

 

4、响应模式

请求的响应包含以下信息。

{
  // `data` is the response that was provided by the server
  data: {},

  // `status` is the HTTP status code from the server response
  status: 200,

  // `statusText` is the HTTP status message from the server response
  statusText: ‘OK‘,

  // `headers` the headers that the server responded with
  // All header names are lower cased
  headers: {},

  // `config` is the config that was provided to `axios` for the request
  config: {},

  // `request` is the request that generated this response
  // It is the last ClientRequest instance in node.js (in redirects)
  // and an XMLHttpRequest instance in the browser
  request: {}
}



此处仅作交流学习,版权归原作者所有。

 

vue中axios安装及使用

标签:from   cti   com   npm   pos   row   set   ofo   send   

原文地址:https://www.cnblogs.com/w-yue/p/11792107.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!