Home > Enterprise >  Call url with axios.get with multiple params Vuejs
Call url with axios.get with multiple params Vuejs

Time:06-17

I'm trying to call an api which have 2 params. thi is the axios call

getData: function (id) {
    let subsidiary = this.$route.query.subsidiaryId;

    axios.get("https://localhost:44391/api/ContractType/ContractTypePhos? 
subsidiaryId =& contractType=", { params: { subsidiaryId: subsidiary, contractTypeId: id } 
})
        .then((res) => {
        if (res.data == "No Pho Founds") {
            swal(res.data);
            this.showGrid = true;
        } else { this.enabledPhos = res.data; }
    })
}

but it didn't work

CodePudding user response:

I believe you have to remove everything after the '?' in the url, so your code will look like this:

getData: function (id) {
  let subsidiary = this.$route.query.subsidiaryId;

  axios.get(
    "https://localhost:44391/api/ContractType/ContractTypePhos", 
    { params: { 
      subsidiaryId: subsidiary, 
      contractTypeId: id 
    }})
    .then((res) => {
        if (res.data == "No Pho Founds") {
            swal(res.data);
            this.showGrid = true;
        } else { this.enabledPhos = res.data; }
    })
}

You shouldn't have spaces in your url strings. The browser will convert them to ' ' which will cause errors.

  • Related