如何在我的代码 nuxtjs 上导入外部 js 和 css

Raf*_*ael 2 javascript nuxt.js

我在 Nuxt.JS 中启动了一个项目,但已经有了 HTML + CSS + JS 的网站。我只需要在 NuxtJS 的设计中包含这些 HTML 即可。

我已经尝试将 css 作为全局范围放入 nuxt.config.js 中,但是这样它将在 SSR 中编译,我不喜欢它。就像在 html 上导入 css、js...

如何将 CSS 和 Javascript 导入到我的页面中?

谢谢

Ejd*_*ien 6

您所要做的就是在页面的导出默认值中包含一个 head 方法。您可以在这里
了解有关 head 方法的更多信息

<script>
export default {
  head () {
    return {
      script: [
        { src: 'path/to/your/js/file.js' }
      ],
      link: [
        { rel: 'stylesheet', href: 'path/to/your/css/file.css' }
      ]
    }
  }
}
</script>
Run Code Online (Sandbox Code Playgroud)

或者

您可以将它们包含在 html 中,就像使用style标签一样

<style src="path/to/your/css/file.css"><style>
<!-- You can also add "scoped" or "lang='sass'" etc in there -->
Run Code Online (Sandbox Code Playgroud)