axios功能和安装使用

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

功能
从浏览器生成xmlhttprequest
从node.js发出http请求
支持Promise API
拦截请求和响应
转换请求和响应数据
取消请求
json数据的自动转换
客户端支持防止xsrf

安装
npm安装

$ npm install axios

bower安装

$ bower install axios

yarn安装

$ yarn add axios

cdn直接使用

基本使用

 

axios.get('/user?ID=12345')
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .finally(function () {
    // always executed
  });

使用老旧浏览器会对您的计算机安全造成威胁。用户可以使用 快乐浏览 来了解主流浏览器,及其版本信息。

如果你是站长或前端工程师,让我们一起放弃低版本浏览器的兼容。

你可能感兴趣的:(axios功能和安装使用)