Want to take a look at our new docs? Our new docs are now in beta. Have fun!

外部资源

如何在 Nuxt.js 应用中使用外部资源?

全局配置

在 nuxt.config.js 中配置你想引用的资源文件:

module.exports = {
  head: {
    script: [
      {
        src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'
      }
    ],
    link: [
      {
        rel: 'stylesheet',
        href: 'https://fonts.googleapis.com/css?family=Roboto'
      }
    ]
  }
}

局部配置

可在 pages 目录内的 .vue 文件中引用外部资源,如下所示:

<template>
  <h1>使用 jQuery 和 Roboto 字体的关于页</h1>
</template>

<script>
  export default {
    head: {
      script: [
        {
          src:
            'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'
        }
      ],
      link: [
        {
          rel: 'stylesheet',
          href: 'https://fonts.googleapis.com/css?family=Roboto'
        }
      ]
    }
  }
</script>
Contribution for this page is now closed. If you would like to contribute please check out our new docs are now in beta. Have fun!

Platinum Sponsors

StoryblokMoovweb Support Us