Q
Q
qwentry2022-04-21 16:40:49
JavaScript
qwentry, 2022-04-21 16:40:49

How to pass axios baseURL vue3?

Good afternoon.

Created vue3 project.
How to pass baseUrl, so that it would not be constantly registered in functions, but only 1 time somewhere?

I understand somehow in the vue.config.js file?

Now I use by type

const url = 'http://localhost:1234/api/example'

            axios
                .post(url, data)
                .then(() => {
                });

And so it turns out in each function I forward localhost:1234/api , and in each file ... I want to get away from this, but I don’t understand how ...
In terms of Nuxt, it was like this
export default {
  env: {
    backendUrl: 'http://localhost:5034/',
  },
}

But it didn’t work out for me ...
Or do I need to import it into main.js later? or ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wonderingpeanut, 2022-04-21
@wonderingpeanut

https://github.com/axios/axios#config-defaults

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question