Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use vuetify in nuxt js as plugin?

I need to use vuetify in my nuxt js project as plugin. I've tried package @nuxtjs/vuetify but get error

Cannot assign to read only property 'base' of object '#'

enter image description here

I've install my nuxt project from official codesandbox online playground in local server and on shared hosting. All the time I got the same error. I tried install node modules using npm and yarn. How I can add fresh vuetify version to last version of nuxt js as plugin with npm package vuetify?

like image 265
Andreas Hunter Avatar asked Jan 06 '20 10:01

Andreas Hunter


People also ask

Is Vuetify a plugin?

vuetify-loader is a treeshaking plugin for Webpack. It gets installed automatically when you install Vuetify using "vue add vuetify".

Does Vuetify work with Nuxt 3?

Enjoy Vuetify alongside Nuxt 3 Everything should now be working as expected and you should now be able to utilize the wide array Vuetify components within your Nuxt pages! Enjoy!

Can you use Vuetify without Vue?

No, you can't run Vuetify without Vue. The reason is pretty simple, most of Vuetify is built with vue and most of those components require their script to run, so everything that's not entirely css based will not work.

Is Nuxt faster than Vue?

Nuxt offers better SEO improvement with its server-side rendering feature, faster development with an auto-generic router, public share features, and management with great configuration options and meta tags methods, automatic code splitting with pre-rendered pages — all of this is impossible or extremely complex to ...


2 Answers

Install vuetify and @mdi/font

Create a file vuetify.js in your plugins folder with the following code:

import Vue from 'vue'
import Vuetify from 'vuetify'

import colors from './../config/colors'

import 'vuetify/dist/vuetify.min.css'
import '@mdi/font/css/materialdesignicons.css'
Vue.use(Vuetify)

export default ctx => {
  const vuetify = new Vuetify({
    theme: {
      themes: {
        light: {
          ...colors
        },
        dark: {
          // colors
        }
      }
    }
  })
  ctx.app.vuetify = vuetify
  ctx.$vuetify = vuetify.framework
}

Edit nuxt.config.js file by adding vuetify to plugins like this

{
  ...
  plugins: ['~plugins/vuetify.js'],
  ...
}
like image 135
Mamadou Hady Barry Avatar answered Nov 12 '22 17:11

Mamadou Hady Barry


I achieved this with the following:

npm install --save vuetify

create a file vuetify.js in your plugins folder with the following code:

import Vue from 'vue'
import Vuetify from 'vuetify'

Vue.use(Vuetify)

Amend your nuxt.config.js:

   plugins: ['~plugins/vuetify.js'],
   build: {
     vendor: ['vuetify']
   }
like image 30
Nate Avatar answered Nov 12 '22 18:11

Nate