[Vuejs]-How to change the dynamic baseUrl Laravel + Vue.js?

5👍

Taken from the official mix documentation, you can use an environment variable by creating a key in your .env prefixed with MIX_:

MIX_BASE_URL=http://mvp.test/api/public/api/

And run php artisan config:clear to be sure the new config is set.

Then, in javascript you can access the variable inside the process.env object:

process.env.MIX_BASE_URL

So you can simply use it like this:

const instance = axios.create({
    baseURL: process.env.MIX_BASE_URL
});

Leave a comment