search
LoginSignup
16

More than 1 year has passed since last update.

posted at

updated at

Nuxt.jsで.envファイルを扱う@nuxtjs/dotenv

@nuxtjs/dotenvを使います

.envファイル作成

下記コマンドでルート配下に.envを作成

touch .env

下記のように環境変数記述

.env.dev
API=http://localhost:8000/api/

nuxt.config.js設定

nuxt.config.js
require('dotenv').config();
const {API} = process.env;

export default {
  env: {
    API
  },
}

動作確認

/pages/index.vue
export default {
  created() {
    console.log(process.env.API)
  }
}

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
What you can do with signing up
16