2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

Posted at

#これまで
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

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?