Inject Vibrant Hues into Your Vuetify Theme in a Nuxt project

I've been struggling to customize the color scheme of my Vuetify theme for my Nuxt project by using (class="") without success. Despite browsing through various related threads, I still can't get it working.

Most discussions on this topic don't provide a direct solution for integrating Vuetify into the project initially, so here's what you need to do:

1. Install vuetify and @mdi/font

2. Create a file named vuetify.js in your plugins directory with the code snippet below:

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
}

3. Call it from your nuxt.config.js file like this:

plugins: ['~/plugins/vuetify.js']

In my situation, when creating a new Nuxt project using npm init nuxt-app@version, you have the option to set up the project with Vuetify by selecting specific configurations. Nuxt then builds the project with Vuetify, resulting in the following configuration in the nuxt.config.js file:

  buildModules: [
    // https://go.nuxtjs.dev/vuetify
    '@nuxtjs/vuetify',
  ],

  vuetify: {
    customVariables: ['~/assets/variables.scss'],
    theme: {
      dark: false,
      themes: {
        dark: {
          primary: colors.blue.darken2,
          accent: colors.grey.darken3,
          secondary: colors.amber.darken3,
          info: colors.teal.lighten1,
          warning: colors.amber.base,
          error: colors.deepOrange.accent4,
          success: colors.green.accent3,
        },
      }
    }
  },

My understanding suggests that adding custom color variables to the existing dark theme in nuxt.config.js should be straightforward. Here's how you can achieve it:

  vuetify: {
    customVariables: ['~/assets/variables.scss'],
    theme: {
      dark: false,
      themes: {
        dark: {
          myColor: '#e456',
          primary: colors.blue.darken2,
          accent: colors.grey.darken3,
          secondary: colors.amber.darken3,
          info: colors.teal.lighten1,
          warning: colors.amber.base,
          error: colors.deepOrange.accent4,
          success: colors.green.accent3,
        },

After defining your custom colors, you can use them in your HTML like this:

<template>
  <v-app class="myColor">
    <v-main>
      <v-container fluid >
        <Nuxt />
      </v-container>
    </v-main>
  </v-app>
</template>

If anyone knows a simpler way to accomplish this, please share your insights!

Below are the details of my Nuxt project:

{
  "name": "code",
  "version": "1.0.0",
  "lockfileVersion": 2,
  "requires": true,
  "packages": {
    "": {
      "name": "code",
      "version": "1.0.0",
      "dependencies": {
        "@nuxt/content": "^1.15.1",
        "@nuxtjs/axios": "^5.13.6",
        "core-js": "^3.19.3",
        "nuxt": "^2.15.8",
        "vue": "^2.6.14",
        "vue-server-renderer": "^2.6.14",
        "vue-template-compiler": "^2.6.14",
        "vuetify": "^2.6.1",
        "webpack": "^4.46.0"
      },
      "devDependencies": {
        "@nuxtjs/vuetify": "^1.12.3"
      }
    },

Answer №1

While you've specified your unique color in the themes.bright section, the theme.dark attribute is toggled to false, which means your application isn't fetching colors from that particular area.

In order for things to function properly, you must place your distinct color in the themes.light segment or switch the theme.dark setting to true.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using d3.js to toggle visibility of bars when clicking on the legend

// Handling the browser onresize event window.onresize = function () { scope.$apply(); }; scope.render = function (data) { var ageNames = d3.keys(data[0]).filter(function (key) { ...

Extract the value of a key from a particular object in a JSON array using JavaScript

I have a JSON structure that looks like this: { map: [ {"key1":"valueA1", "key2":"valueA2", "key3":"valueA3"}, {"key1":"valueB1", "key2":"valueB2", "key3":"valueB3"}, {"key1":"valueC1", "key2":"valueC2", "key3":"valueC3"}, .... an ...

Using gulp to duplicate files from a specific directory nestled within a larger folder structure

I'm trying to figure out how to address this issue: My goal is to transfer all fonts from bower_components to .tmp/assets/fonts. However, the complication arises with some fonts being .svg files. If I were to use the following code in a typical manne ...

Attempting to unravel the mysterious code written in hexadecimal

Currently, I am immersed in a programming challenge and find myself stuck on the last question. This particular task requires deciphering a hexadecimal code to unveil a hidden message. The answer needs to start with 0x, indicating another hexadecimal value ...

Struggling to generate a TrackballControls instance

Every time I try to create a TrackballControls object, I encounter an error message stating "THREE.TrackballControls is not a constructor". Here's a simple example: <!doctype html> <html> <head> <title>Trackball Contr ...

Using the mt-downloader module in a Node application is a straightforward process

Hey there, I'm looking to incorporate the Multi downloader module into my project. I've checked out the GitHub link, but unfortunately, there are no examples provided on how to actually use this module. I came across this example and tried implem ...

JQuery Chosen extension - Go back to "Choose an option"

This is a select element with the Chosen plugin applied to it: <label class="radio-inline"><input type="radio" name="reset" value="reset">Reset</label> <select id="listclient"> <option value=""></option> <option val ...

Is it possible to embed PHP code within HTML?

Can you identify any issues in the code below? Everything works fine when I remove the PHP variable $var, but I actually need to insert a value of 5000 into it. echo '<div id="img1" style="position:absolute;left:81px;top:127px;width:12px;height:12 ...

Error encountered: Multer TypeError - fields does not have a function called forEach

I'm currently working on a metadata reader using multer in node.js with express on c9. I've spent some time searching for solutions to my issue, but it seems like no one else has encountered the error I am facing: TypeError: fields.forEach is no ...

MUI-Datatable: Is there a way to show the total sum of all the values in a column at once

I have a column displaying the Total Amount, and I am looking for a way to show this totalAmount. After conducting some research, it seems like onTableChange is the key. Currently, it effectively displays all of the data using console.log("handleTab ...

Determining the occurrence of a specific value within an array using JavaScript

Can you help refine my function? I've created one that counts the number of 7s in an array, but it only counts each element once even if it has multiple 7s. How can I modify it to calculate the total number of 7s in the array without missing any? Plea ...

How can one obtain the object (whether it be a string or an array) named NAME?

Can someone help me create a prototype like this: Array.prototype.getName=function(){ [...]return arrayName; } Then I want to be able to do this: x = new Array; alert(x.name); and have "x" displayed in the alert. I'm currently developing on Chrom ...

"Master the art of using express and jade to loop through data and generate dynamic

Hey there! I have a question regarding node.js. When working with express, we typically have multiple files such as app.js, index.jade, index.js, and server.js where most of the server logic resides. Let's say we have two objects defined in server.js ...

Trouble with linking an external JavaScript file in HTML document

I'm having some trouble including an external JavaScript file in my HTML. I followed the steps but the pie chart is not showing up as expected. Can someone please take a look and let me know if I missed anything? Here's the link to where I got th ...

Having trouble connecting v-model to vue-date-picker

My experience with the vue-date-picker and v-model for two-way data binding has been interesting. Initially, I set the value to a date (referred as startDate in this case) and printed the passed value (i.e. startDate) in the console. The initial value pa ...

"NextAuth encounters an issue while trying to fetch the API endpoint: req.body

Trying to implement authentication in my Next.js app using NextAuth.js, I've encountered an issue with the fetching process. Here's the code snippet from the documentation: authorize: async (credentials, req) => { const res = await fetch ...

Using JQuery to execute a script on form elements added via ajax

I've encountered an issue with a form element that is fetched via ajax upon request. I'm attempting to make an ajax request on the dynamically inserted text box to find a location as it's being typed. Strangely, the code works for the first ...

Vue.js 3 Single File Component: Prop

Whenever I utilize a prop in my Single File Component (SFC), the prop appears empty or does not display at all. First, I have an ActionButton.vue file: <script setup> defineProps({ actionButtonOne: { type: String } }) </script> ...

Learn how to dynamically activate an icon in Angular to enhance user interaction

HTML Code: The Zoom Component <div class="zoom py-3"> <i nz-icon nzType="minus" (click)="zoomToggle(false)" nzTheme="outline"></i><br> <i nz-icon nzType="plus" (click)=&q ...

Guide on resolving a "res is not defined" issue in Node.js

I've been struggling to test the controller logic for a user validation module, but I keep encountering an error that says "res is not defined" even after trying to define it. How can I properly define it so that it runs through the condition statemen ...