Home > Web Front-end > JS Tutorial > body text

Introduction to the encapsulation of axios in vue (explanation with examples)

不言
Release: 2019-01-17 10:08:24
forward
2803 people have browsed it

This article brings you an introduction to the axios package of Vue (example explanation). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

I started to get in touch with vue at the beginning of 2018. I initially used vue-resource, but I heard that axios is pretty awesome, so I was ready to jump in and give it a try. After all, vue-resource has officially given up maintenance

Introduction to the encapsulation of axios in vue (explanation with examples)

The baseURL is the request path of our backend interface (the last url of the request=baseURL the request url of axios)
withCredentials This field is to let Our request carries cookie information. If it is not set, the default value is false, and the session will be lost, and the information in the session cannot be obtained.

Introduction to the encapsulation of axios in vue (explanation with examples)

Introduction to the encapsulation of axios in vue (explanation with examples)

request request interceptor, where we can operate before making some requests. For some requests, according to the request carrying Parameters passed in

(for example, the following request has no loading effect)

Introduction to the encapsulation of axios in vue (explanation with examples)

# #Some projects need to request several background services. Just change the baseURL of the request directly in the request interceptor. .

There are also some interfaces that need to change the header information. Just modify it directly.
ps: I have to complain about vue-resource's pitfalls in changing the header in the request interceptor. I want to change the header. information, you must first set the emulateJSON field to false

Introduction to the encapsulation of axios in vue (explanation with examples)

axios requests the default headers Content-Type is 'application/x-www-form-urlencoded;charset=UTF-8'

@RequestParam in the post request backend (backend framework ssm) Controller cannot get the request parameter
At this time, the request Just process the parameters with qs.stringify() or ask the backend to change to obtain the parameters from @RequestBody

When the request header is application/json, there is no need to do any processing on the request parameters

response response The interceptor is mainly used to handle request timeout situations.

The above is the detailed content of Introduction to the encapsulation of axios in vue (explanation with examples). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!