Setting Up Nuxt 3 with Vuetify 3: A Comprehensive Guide

sarveshk76

Sarvesh S. Kulkarni

Posted on November 16, 2023

Setting Up Nuxt 3 with Vuetify 3: A Comprehensive Guide

Nuxt 3 and Vuetify 3 are powerful tools that can help you build modern, responsive, and performant web applications. Nuxt 3 provides a framework for building Vue.js applications, while Vuetify 3 offers a comprehensive UI component library. Combining these two technologies allows you to create stunning and functional web apps with ease.

Prerequisites

Before you begin, ensure you have the following prerequisites:

  1. Node.js: Install Node.js, which includes the npm package manager.
  2. Vite: Install Vite, a front-end build tool used by Nuxt 3.
  3. Basic Vue.js Knowledge: Familiarity with Vue.js concepts and syntax is recommended.

Creating a Nuxt 3 Project

  1. Create a Project Directory: Create a new directory for your Nuxt 3 project.
  2. Initialize Nuxt: Open a terminal window and navigate to the project directory. Run the following command to initialize a new Nuxt 3 project:
npx nuxi init nuxt-app
Enter fullscreen mode Exit fullscreen mode

This command will create a basic Nuxt 3 project.

Installing Vuetify 3

Install the required Vuetify modules as dependencies:

npm i -D vuetify vite-plugin-vuetify
npm i @mdi/font
Enter fullscreen mode Exit fullscreen mode

Creating a Vuetify Plugin

  1. Create a Plugins Folder: Create a directory named plugins inside the Nuxt 3 project root.
  2. Create the Vuetify Plugin: Inside the plugins directory, create a file named vuetify.ts.
  3. Import Vuetify: Import Vuetify and its components using the following code:
import { createVuetify } from 'vuetify'
Enter fullscreen mode Exit fullscreen mode

Configure And Export Vuetify : Create a Vuetify instance and configure its options:

   export default defineNuxtPlugin((nuxtApp) => {
   const vuetify = createVuetify({
    icons: {
      defaultSet: 'mdi',

    },
   })
   nuxtApp.vueApp.use(vuetify)
})

Enter fullscreen mode Exit fullscreen mode

Integrating Vuetify with Nuxt 3

Import Vuetify Plugin And Enable Sass/SCSS Support: In the nuxt.config.js file, import the Vuetify plugin:

import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'

export default defineNuxtConfig({
  css: [
    'vuetify/lib/styles/main.sass',
    "@mdi/font/css/materialdesignicons.css",
  ],
  build: {
    transpile: ['vuetify']
  },
});
Enter fullscreen mode Exit fullscreen mode

Use Vuetify Components: You can now use Vuetify components in your Vue.js templates. For example, to add a button:

<v-btn>Click Me</v-btn>
Enter fullscreen mode Exit fullscreen mode

Running the Application

To start the Nuxt 3 development server, run the following command in the project directory:

npm run dev
Enter fullscreen mode Exit fullscreen mode

This will start the server and open your application in the browser. You can now start developing your Nuxt 3 application with Vuetify 3.

💖 💪 🙅 🚩
sarveshk76
Sarvesh S. Kulkarni

Posted on November 16, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related