Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
16
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

updated at

Organization

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)
  }
}
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
16
Help us understand the problem. What are the problem?