Home > Web Front-end > JS Tutorial > Use a=a&b=b to implement post request in vue

Use a=a&b=b to implement post request in vue

php中世界最好的语言
Release: 2018-05-15 10:43:58
Original
1443 people have browsed it

This time I will bring you how to use a=a&b=b to implement post request in vue, and use a=a&b=b to implement post request in vue. What are the precautions? The following is a practical case, let’s take a look.

During the vue development process, we will always encounter some problems. Of course, no problem can stop us from moving forward. Without further ado, here are the request parameters that I used during the development process. Problems encountered

1. When there is no background data for the time being, most of the parameters of the post request will be written in the format of name:a,age:b

import axios from 'axios';
axios.post(url,{
    name:'0',age:''
    },{emulateJSON: true}, {  // 这里是跨域写法
    headers:{"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",}  // 这里是跨域的写法
    }).then(reponse=>{
     console.log(reponse)
      this.tableData=reponse.data.data
    })
Copy after login

There is no problem with this way of writing Yes,

2, if the background has been written, but the post request needs to be written in the form of name:a&age:b , your writing method above will not be able to request data. At this time, we have to use A plug-in to solve this problem

2.1, Install qs

 npm install --save axios vue-axios qs
Copy after login

2.2, add

    import qs from 'qs';
     import axios from 'axios';
axios.post(url,qs.stringify({  // 通过qs.stringify()将对象解析成URL的形式
    name:'0', age:'2'
    }),{emulateJSON: true},{
    headers:{"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",}
    }).then(reponse=>{
     console.log(reponse)
     this.tableData=reponse.data.data
    })
Copy after login

to the requested page. I believe you have read the case in this article. After mastering the method, please pay attention to other related articles on the php Chinese website for more exciting content!

Recommended reading:

Vue implementation of PopupWindow component usage steps analysis

vue jquery lodash top suspension fixed function implementation when sliding Detailed explanation

The above is the detailed content of Use a=a&b=b to implement post request in vue. 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