2

I starting a project in Nuxt.JS but already have my site in HTML + CSS + JS. I need just include these HTML on design of NuxtJS.

I have already tried to put the css as a global scope inside nuxt.config.js however in that way it will compile in SSR, and I would not like it. Just like import on html the css, js...

How could I import CSS and Javascript into my pages?

Thanks

1 Answer 1

6

All you have to do is to include a head method in your page's export default.
You can learn more about the head method 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>

OR

You can include them as if you'd do in html with style tag

<style src="path/to/your/css/file.css"><style>
<!-- You can also add "scoped" or "lang='sass'" etc in there -->
Sign up to request clarification or add additional context in comments.

2 Comments

FYI: if it's dynamic page, like _id, if you would navigate from page with ID 1 to page with ID 2, your external script won't load, you have to refresh a browser or re-render your page component.
@Ejdrien Can I use conditions for import CSS in link section?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.