Help us understand the problem. What is going on with this article?

Vue.jsコンポーネント内でLaravelの .envを使用する方法

これまで

axiosインスタンスの作成(カスタム設定)をしたいときのbaseURLの記述部分で直接記述しても良いのか?という疑問に当たりました。

また、本番環境・開発環境などとこれから設定値も切り替えたいものでもありました。

let $axios = axios.create({
    baseURL: 'http://localhost:8000',
    timeout: 5000,
    headers: {
        'Content-Type': 'application/json'
    }
})

対処

process.env.[変数名]でアクセスできる.

Laravel環境変数

let $axios = axios.create({
    baseURL: process.env.MIX_BASE_URL,
    timeout: 5000,
    headers: {
        'Content-Type': 'application/json'
    }
})
env
MIX_BASE_URL=http://localhost:8000

所存

環境で変化するものはenvに入れてみようかなと思います(仮)

参考

https://medium.com/@patrickcurl/using-laravel-env-variables-inside-vue-js-components-29faa9a344c5

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした