axios

Official website:
 
 
Import method:
$ npm install axios
//Use Taobao source $ cnpm install axios //Or use cdn: <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
When installing other plug-ins, you can directly introduce them in main.js and use Vue.use() to register, but axios is not a vue plug-in, so Vue.use() cannot be used, so you can only use Vue.use() for each request that needs to be sent. Immediate introduction in components.
In order to solve this problem, after introducing axios, we modified the prototype chain to make it more convenient to use.
//main.js
import axios from 'axios' Vue.prototype.$http = axios
After adding these two lines of code in main.js, you can use the $http command directly in the methods of the component
methods: { postData () { this.$http({ method: 'post', url: '/user', data: { name: 'xiaoming', info: '12' } }) }
Let's introduce the specific use of axios:
 
1 $http.post('/user', { firstName: 'Fred', lastName: 'Flintstone' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
2、 axios.get('/user/12345') .then(function(response) { console.log(response.data); console.log(response.status); console.log(response.statusText); console.log(response.headers); console.log(response.config); });

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325122693&siteId=291194637