Axios cross-domain

I have set

in main.js.
axios.defaults.withCredentials=true;
axios.defaults.crossDomain=true;
axios.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";

then I used the axios, project in a component that needs to carry cookie over. The approximate function is as follows

this.$axios.post("http://pj.dianmila.com/supersolid/supersolid_api.php?a=list",{offset:self.swiperlen},{headers: {"Content-Type":"application/x-www-form-urlencoded"}}).then(function(res) {
                        var datajson = res.data;
                        if(datajson.state == 1) {
                            for(let i in datajson.list) {
                                self.swiper.off("reachEnd")
                                self.swiperlist.push(datajson.list[i])
                                self.swiperlenPP;
                            }
                        } 
                    }).catch(function (error) {
                    alert("")
                console.log(error);

then you don"t have to write the following headers setting without passing parameters, but once I bring the parameters in, the headers of the global setting is invalid. You must add the following headers before you can pass it through. And even if it is passed, you will see that {offset:5}:
will be added for no reason: the server cannot recognize it. Ask for a great solution

.

problem description

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

topic description

sources of topics and their own ideas

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

May.12,2021

normally corresponds to content-type: application/json;charset=UTF-8
solution is to add transformRequest to process the data myself, I choose to use qs to process, address .

axios.post('http://pj.dianmila.com/supersolid/supersolid_api.php?a=list',{offset:1},{
  headers: {'Content-Type':'application/x-www-form-urlencoded'},
  transformRequest: [function (data) {
    return Qs.stringify(data)
  }],

  }).then(function(res) {
    console.log(res)
  }).catch(function (error) {
    console.log(error);
  })





clipboard.png

Menu