Nesrine Missaoui
Nesrine Missaoui

Reputation: 19

Call url with axios.get with multiple params Vuejs

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

Upvotes: 0

Views: 2072

Answers (1)

Duha
Duha

Reputation: 61

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 '%20' which will cause errors.

Upvotes: 2

Related Questions