A
A
Alexey Kot2019-05-21 17:03:30
JavaScript
Alexey Kot, 2019-05-21 17:03:30

How to set the default API endpoint in Axios, which is a file?

I use Axios to create a SPA on Vue.js
There is a backend with an address like:
https://backend.site.com/api.php
Any requests have the following pattern, examples:

https://backend.site.com/api.php?cmd=users
https://backend.site.com/api.php?cmd=goods&limit=20
https://backend.site.com/api.php?cmd=posts&page=2

I create an Axios instance:
const webclient = axios.create({
  baseURL: "https://backend.site.com"
})

But now in every request method I have to put in something like:
webclient.get("api.php?cmd=users").then ...
I can't figure out how to take this into account when instantiating Axios. I tried to do params, but it did not work out to get the desired result.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question