4
1

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.

Nuxt.jsで外部のjs,cssファイルを読み込む方法

Posted at

Nuxt.jsで外部のjs,cssファイルを読み込む方法になります。

共通で読み込む場合

共通で外部ファイルを読み込む場合は、nuxt.config.jsで設定します。

nuxt.config.js
export default {
  head: {
    script: [
      {
        src: 'https://demo.js'
      }
    ],
    link: [
      {
        rel: 'stylesheet',
        href: 'https://fonts.googleapis.com/css?family=Roboto'
      }
    ]
  }
}

ページ毎に読み込む場合

ページごとに外部ファイルを読み込む場合は、pagesディレクトリのvueファイルで設定します。

page.vue

<script>
export default {
  head() {
    return {
      script: [
        {
          src: 'https://demo.js'
        }
      ],
      link: [
        {
          rel: 'stylesheet',
          href: 'https://fonts.googleapis.com/css?family=Roboto'
        }
      ]
    }
  }
}
</script>

4
1
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?