vue中axios安裝及使用

axios  基於HTTP客戶端的瀏覽器和node.js

網址連接:https://github.com/axios/axioshtml

 

 

一、特徵:

  • 製做,使XMLHttpRequest從瀏覽器
  • 製做,使http來自node.js的請求
  • 支持承諾API
  • 攔截請求和響應
  • 轉換請求和響應數據
  • 取消請求
  • JSON數據的自動轉換
  • 客戶端支持防止XSRF

 

 

二、安裝:

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>

 

 

三、配置使用:

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')) });

 

 

四、響應模式

請求的響應包含如下信息。node

{
  // `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: {} }



此處僅做交流學習,版權歸原做者全部。ios

相關文章
相關標籤/搜索