1

I am currently developing a nuxt application using an admin template. I am familiar with vue js but the loading assets within nuxtjs part is a little bit confusing for me. I am converting the admin template pages to nuxt page components. I will talk about the email page (one of many pages with the same issue) in this question.

The base admin page has various CSS files loaded on the page. Some are global level some are page level. I have added the global CSS in the nuxt.config.js file

   /*
   ** Global CSS in nuxt.config.js
   */
  css: [
    // long list of global css files
  ],

And I tried loading the page level CSS like this.

  // pages/email.vue
export default {
  head: {
    bodyAttrs: {
      class:
        'vertical-layout vertical-menu-modern content-left-sidebar email-application navbar-sticky footer-static',
      'data-open': 'click',
      'data-menu': 'vertical-menu-modern',
      'data-col': 'content-left-sidebar'
    },
    script: [
      { src: '/app-assets/js/scripts/pages/app-email.js' },
      { src: '/app-assets/vendors/js/editors/quill/quill.min.js' }
    ]
  },
  css: ['~/static/app-assets/css/pages/app-email.css'], // this way doesnt work
  middleware: 'auth'
}

When I add the page level CSS like this it doesn't work at all. The styles are not loading. But, as expected, when I add the same style sheet in the global styles in nuxt.config.js, IT WORKS!!

   /*
   ** Global CSS in nuxt.config.js
   */
  css: [
    // long list of global css files
    '~/static/app-assets/vendors/css/editors/quill/quill.snow.css', //works like charm
  ],

Any idea what I am missing here? Cheers.

1 Answer 1

1

You need to put your CSS in an link array:

link: [
        { rel: 'stylesheet', href: '/path/to/your.css' }
      ]

https://nuxtjs.org/faq/

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. That worked. Also, I had to remove the '~/static/' part while mentioning the path.

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.