Home > Web Front-end > JS Tutorial > The concept and usage of Axios in vue.js

The concept and usage of Axios in vue.js

零到壹度
Release: 2018-04-12 14:12:52
Original
2550 people have browsed it

This article shares with you the concept and usage of Axios in vue.js. It has a certain reference value. Friends in need can refer to it

1. What is Axios

https://www.kancloud.cn/yunye/axios/234845This is the official Chinese document, you can take a look

Axios is a promise-based HTTP library that can be used in browsers and node.js. Like ajax, it is used to interact with the background, but there are differences between the two.

The following is from Zhihu A paragraph:

axios is an encapsulation of ajax technology through promise, just like jQuery implements ajax encapsulation.

In simple terms: Ajax technology realizes partial data refresh of web pages, and axios realizes the encapsulation of ajax.

Axios is ajax Ajax is more than axios, This passage can well explain the relationship between the two

juuery Ajax is mainly for mvc programming , it is increasingly unable to keep up with the current rhythm, and juuery is too big. It is not worth the gain to introduce jquery just for ajax. With the rise of more and more frameworks, the road of jquery is getting narrower and narrower

axios has the following characteristics

##                                          

Support Promise API # Client

Support to prevent csrf

##Q The interface of concurrent requests (important, it is convenient for many operations) ## This is relatively small compared to Ajax, Axios is smaller

## This

Having said so much, everyone should understand the difference between the two, so let me introduce to you the specific usage

                                                                                                                                                                                                                    

    

同事支持多个请求  

function getUserAccount() {
  return axios.get('/user/12345');
}

function getUserPermissions() {
  return axios.get('/user/12345/permissions');
}

axios.all([getUserAccount(), getUserPermissions()])
  .then(axios.spread(function (acct, perms) {    
  // 两个请求现在都执行完成
  }));
Copy after login

如何安装呢

          使用 npm    :

        $ npm install axios
Copy after login

    使用 bower:

        $ bower install axios
Copy after login

使用 cdn:

        <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
Copy after login

The above is the detailed content of The concept and usage of Axios in vue.js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template