Has recently been writing vue project, found that many of the pit is never seen before, this is a good thing, after all, on the process of the pit is a learning process, a later date may be more update vue, after all is written in the project of vue, I write may be something relatively simple plain, but I after all is a vue beginners. Is not a god, so according to their own learning and use of some knowledge of the continuous from shallow to deep to promote, master when review, novice when learning.

For security purposes, we only do two kinds of processing requests when we process data. The first type is GET, which is query. All queries are GET requests, updates, additions and deletions are POST requests. So when I interact with the back end of the request using AXIos, then in the process of writing, sometimes need to pass parameters, such as conditional query, need to pass the condition, then this time involves the problem of the value type, I began to write:

searchIndoBySel : function(){
let that = this;
        this.$axios({
        method : ‘get', url : url, data:{ name = that.name, age = that.age, sex = that.sex } }).then(function(res){ if(res.data.message == 'Success ') {that. TableDate = res. Data. The result; }else{
            console.info(res.data.message)
         }
    }).catch(function(err){
            console.info(err.data.message)
    })
}
Copy the code

I wrote the code directly in the CSDN editor, so I didn’t verify whether it was correct or not, but it was basically like this, it was a simple request to send, but I couldn’t get the information of the request header during the request. At first, I always thought it was the problem of the back end. However, there was no problem later when I directly used Postman to request, so the problem I located was that the format of sending was wrong, so how to change it? So I started to add various json.stringify and other format conversion, but it didn’t help (mostly because I’m not good at it, I can leave the battlefield.)

Then I opened the vue document and started to look through it. Later I realized that it is wrong to request parameters. The correct get request should be written like this:

searchIndoBySel : function(){
let that = this;
        this.$axios({
        method : ‘get', url : url, params:{ name = that.name, age = that.age, sex = that.sex } }).then(function(res){ if(res.data.message == 'Success ') {that. TableDate = res. Data. The result; }else{
            console.info(res.data.message)
         }
    }).catch(function(err){
            console.info(err.data.message)
    })
}
Copy the code

Yes, there’s a little bit of a difference, but there’s a big difference. Now, let’s get to the point. In today’s lecture, let’s talk about the difference between Data and Params.

Data is used for post requests, so its parameters are actually written in the request body, rather than spelled behind the URL as parameters, then get requests are spelled behind the URL for passing parameters, so here is the need to use params keyword. This is used for GET requests. Normally, our GET requests operate on parameters as URL concatenated objects, so using params is the correct solution.

Due to the reason of working hours, I can only update my blog at night every day, so I won’t write more. I’m sorry for the bad, incomplete or not rigorous writing. Learn from each other.

Thanks for reading!