Front-end projects built with Vue scaffolding usually use Axios encapsulated interface requests. The methods introduced in the project will not be introduced in detail. This article mainly introduces interface calls and different forms of parameter passing methods. 1. Get request:Get request is relatively simple, usually concatenating the parameters into the URL and connecting them with ? & or in the following way: this.axios.get(this.getWxQyUserInfoUrl, { params: { agentid: this.doLoginParams.agentid, code: this.doLoginParams.code } }) 2. Post request: 1) Form data FormData parameter transmission method ① axios configuration, set the request header: Header axios.interceptors.request.use(config => { //Specify the content type that the client can receive config.headers.Accept = "application/json, text/plain,*/*" return config; }, error => Promise.error(error) ) Similar to setting up separate response exception handling: axios.interceptors.response.use(response => { // System error return response; }, error => { // You can redirect the request error to the network exception page as needed console.log("The main page captures axios exception: "+JSON.stringify(error)); // router.push({ // path: "/networkerr", // name: "networkerr" // }); }) ② In the request interface encapsulation file, introduce the qs middleware. When the request method is post, the parameters need to be converted to the format through the qs.stringify function import qs from 'qs'; Vue.prototype.$qs = qs; Then you can directly use var qs = require('qs'); this.axios.post(this.postUrl,qs.stringify({"value1":100,"value2":"123"})) 2) JSON string parameter passing method ① axios configuration, set the request header: Head this.axios.defaults.headers['Content-Type'] = 'application/json; charset=UTF-8'; //Configure request header ② The request parameters are converted using the SON.stringify() function, or they can be passed directly without conversion. this.axios.post(this.imageSaveUrl, JSON.stringify(params)) 3. Expansion and Supplement Finally, attach the setting webservice interface to directly return the response in json format instead of xml format: Context.Response.Charset = "utf-8"; //Set the character set type or GB2312 Context.Response.ContentEncoding = System.Text.Encoding.UTF8; //or System.Text.Encoding.GetEncoding("GB2312"); Context.Response.Write(jaoData); Context.Response.End(); This is the end of this article about Vue + Axios request interface method and parameter passing. For more related Vue Axios request interface content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of writing and using Makefile under Linux
>>: Enabling or disabling GTID mode in MySQL online
1. Document flow and floating 1. What is document...
1. Download the ElasticSearch 6.4.1 installation ...
Preface This article mainly introduces the method...
Preface Docker has been very popular in the past ...
ModSecurity is a powerful packet filtering tool t...
Preface I feel like my mind is empty lately, as I...
This article example shares the specific code of ...
When I installed php56 with brew on mac , I encou...
This article mainly introduces the solution to th...
This article shares the specific code of Vue to a...
Preface: When designing a table in MySQL, MySQL o...
Preface This article mainly introduces the releva...
The HTTP status code is a 3-digit code used to in...
Table of contents 1. Mysql data structure 2. The ...
We need to first combine the air quality data wit...