Good day.
When i do the following api call with axios it works just fine but when i try to use a variable in said api call i get a cors error. What am i doing wrong?
When i use it without a variable, this works just fine:
somecall({state}){
axiosB
.get(“/lmao/10.0.0.190”)
.then(res =>
state.response = res.data);
console.log(state.response)
}
When i use a variable to perform the api call, this gives me a CORS error:
somecall({state, ip}){
axiosB
.get(“/lmao/“, ip)
.then(res =>
state.response = res.data);
console.log(state.response)
}
The value when trying to pass is 10.0.0.190 in this case.
Solution :
Assuming you’re using Vuex (are you?), the syntax should be:
somecall({state}, ip){
axiosB
.get(“/lmao/“ + ip)
.then(res =>
state.response = res.data);
console.log(state.response)
}
Note that the payload comes as a second argument after the deconstructed context, rather than together with it.
Or the problem may be with this line:
.get(“/lmao/“, ip)
and may need to be changed as above.