簡體   English   中英

如何在我的代碼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中進行編譯,我不希望這樣做。 就像在html上導入css,js ...

如何將CSS和Javascript導入頁面?

謝謝

您要做的就是在頁面的導出默認值中包含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>

要么

您可以像使用style標簽在html中那樣包含它們

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM