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

how to import external js and css on my code nuxtjs

我在 Nuxt.JS 开始一个项目,但我的网站已经在 HTML + CSS + JS。我只需要在 NuxtJS 的设计中包含这些 HTML。

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

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

谢谢

您所要做的就是在页面的导出默认值中包含一个 head 方法。
可以详细了解head方法here

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

您可以像在 html 中使用 style 标签

一样添加它们
<style src="path/to/your/css/file.css"><style>
<!-- You can also add "scoped" or "lang='sass'" etc in there -->