vue+axios realizes data interaction

php中世界最好的语言
Release: 2018-05-09 09:38:59
Original
2266 people have browsed it

This time I will bring you vue axios to implement data interaction. What are theprecautionsfor vue axios to implement data interaction. The following is a practical case, let's take a look.

axios Promise-based HTTP request client, which can be used in browsers and node.js at the same time

The network communication library officially recommended by Vue is no longer vue-resource, it is recommended to use axios. So I studied it and summarized it as follows.

1. Functional features

1. Send XMLHttpRequests requests in the browser
2. Send http requests in node.js
3. Support Promise API
4. Intercept requests and responses
5. Convert request and response data
6. Automatically convert JSON data
7. Client supports protecting security from XSRF attacks

2. Axios installation method (officially gives 3 methods)

1. npm installation

$ npm install axios

2. Bower installation

$ bower install axios

3. Use cdn directly

Copy after login

3. Installation steps

Here I use npm method steps:

①First enternpm install axios in npm

②Add configuration to main.js

import axios from ‘axios' Vue.prototype.$http = axios
Copy after login

##4. Request Example

Click to get the data to get the data you want

   
Copy after login
Rendering:

I believe you have read this article You have mastered the case method. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

How does JS store original values and reference values

JS uses regular expressions to determine date of birth

The above is the detailed content of vue+axios realizes data interaction. 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