A guide on setting up custom themes in Vue.js with TypeScript

I've been trying to update the color scheme of a Vue template (using vuetify) that I'm working with, but after spending hours on the documentation, I'm at a loss for what to do next.

Here is my main file:

//src/main.ts

import '@babel/polyfill';
// Import Component hooks before component definitions
import './component-hooks';
import Vue from 'vue';
import './plugins/vuetify';
import './plugins/vee-validate';
import App from './App.vue';
import router from './router';
import store from '@/store';
import './registerServiceWorker';

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount('#app');

The vuetify plugin file:

//src/plugins/vuetify.ts

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

Vue.use(Vuetify, {
  theme: {
      themes: {
          light: {
            primary: '#17242d', 
          },
          dark: {
            primary: '#17242d',
        },
      },
    },
});

I've tried various ways of defining different themes in the vuetify.ts file, but nothing seems to change the colors of any components that reference "primary", for example.

Other users appear to have had success with a similar approach: https://forum.vuejs.org/t/vuetify-how-to-add-a-custom-color-theme-after-create-the-project/40241/2

Am I overlooking something? Where should I focus my attention next?

EDIT 1: I removed the reference to vuetify.min.css in main.ts. Now I can briefly see my chosen color before it reverts back to the default after restarting the server.

EDIT 2: By using the web inspector, I discovered that the primary color is being overridden with !important (indicating that this definition takes precedence over all others). How can I locate where that definition is coming from?

Answer №1

Instead of bringing in Vuetify from the node_modules directory in your main.ts, consider importing it from your plugins folder.

Therefore, in your main.ts, instead of

import Vuetify from 'vuetify';

you can try this approach:

import './src/plugins/vuetify.ts';

Answer №2

//src/plugins/vuetify.ts
import Vue from "vue";
import Vuetify from "vuetify/lib/framework";
import "vuetify/dist/vuetify.min.css";

Vue.use(Vuetify);

export default new Vuetify({
  theme: {
    themes: {
      light: {
        primary: "#17242d",
      },
      dark: {
        primary: "#17242d",
      },
    },
  },
});

//src/main.ts
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import vuetify from "./plugins/vuetify";

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  vuetify,
  render: (h) => h(App),
}).$mount("#app");

Repository containing the live demo

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

Issue with Pure Javascript FormData upload involving files and data not successfully processing on PHP end

My file upload form follows the standard structure: <form id="attachform" enctype="multipart/form-data" action="/app/upload.php" method="POST" target="attachments"> <!-- MAX_FILE_SIZE must precede the file input field --> <i ...

What is the best way to monitor the elements within ngRepeat in AngularJS?

Hello everyone, I am facing a minor issue that I seem unable to resolve. I have a search input field that allows users to search through a table in all columns. However, I am struggling to track the items in ngRepeat effectively. Below is the search inpu ...

Two Ajax Requests Simultaneously

I am currently faced with the challenge of handling two requests simultaneously. The first request involves executing a lengthy PHP script that takes 10 minutes to complete (I cannot modify it using JavaScript, so that's not an option). The second ...

Setting the default selection in AngularJS based on the URL entered

I've encountered an issue with a dropdown menu in my AngularJS version 1.4 application. The dropdown menu contains links to different sections of the page. The problem arises when I directly enter the page URL - instead of selecting the correct link f ...

Next.js Troubleshooting: Unexpected Issue with 'use client' Triggering Error in React Client Component

Keeping it simple, here is a useState function that I am using: 'use client' import {useState} from 'react'; const Home = () => { const [fruit, setFruit] = useState('apple'); return ( & ...

AJAX is not displaying the expected output

Seeking help on calling a PHP method from JavaScript to query a database and integrate the results into JS functionality. The current 'console.log(output)' in my Ajax returns: "array (size=1) 'action' => string 'getResults&apos ...

Encountering the error message "Function.prototype.bind.apply(...) cannot be invoked as a constructor

I'm attempting to implement Controller Inheritance in AngularJS (1.6.9), but encountering an error in the console: Function.prototype.bind.apply(...) is not a constructor. Here's the snippet from the HTML file: <!-- Controller Inheritance --& ...

Adjust image size as the page is resized

My challenge is to resize images that are typically too large for the current window size, ensuring they fit within 85% of the client window. I tried creating a function utilizing onload and onresize events but encountered issues. function adjustImages(){ ...

Increase the day count by 1 on every third cycle

I've been working on a code to increment the days in a date variable every third iteration using modulus. While I have managed to get the logic for every third iteration right, the day doesn't seem to increase by 1. I searched online and found s ...

What are the steps to implement character movement in a 2D game using JavaScript?

I'm having trouble getting the image with the ID "yoshi" to move around in my 2D game document.onkeydown = (e) => { if (e.keyCode == 37) yoshi.style.left = yoshi.offsetLeft - 5 + "px"; else if (e.keyCode == 38) yoshi.style.top = yoshi.offset ...

Developing dynamic 3D cubes

In my latest project, I am attempting to construct a unique structure composed of 3D cubes arranged in a stacked formation. Each of the individual cubes within this structure is designed to be interactive for users. When a user hovers over a cube, it trigg ...

Creating a grid surrounding a box using Three.js

I have recently designed a box buffer geometry with dimensions of 8x8x8. To enhance its appearance, I am looking to add a grid around it that aligns with these dimensions (specifically having 64 squares on each side). Does anyone know of any effective me ...

Customizing the appearance of a data field in Angular-ui-grid: Tips and tricks

In my quest through the angular-ui-grid documentation, I have been unable to locate any mention of "CellFormatters" which were utilized in a previous project a few years back. The purpose of the "CellFormatters" was to present a text representation of the ...

The functionality of $render ceased to operate effectively with the release of angular 1.2.2, particularly in relation

Yesterday, I upgraded from angular 1.0.8 to angular 1.2.2 and encountered a problem where the $render function in the directive below is no longer firing, despite fixing other issues that arose. Has anyone else experienced this issue before? ...

Removing data from a table using an identifier in Typescript

Recently, I have made the switch from using Javascript to TypeScript. However, I am facing an issue while trying to delete data from a table in my code. Whenever I attempt to delete data, I encounter this error message: Property 'id' does not e ...

Creating a subdocument in Mongoose involves using MongoDB along with Node.js. Here's how you

I am currently working on incorporating an array of comments as a subdocument within my main document of posts using JavaScript and Mongoose. Despite my efforts with the updateOne method, I am encountering issues when trying to use the save parameter. Addi ...

Can I use npm's jQuery in an old-school HTML format?

I am looking to incorporate jQuery into a project without having to rely on the website or CDN for downloading the library. As someone new to npm, I am curious to know if following these steps would be advisable or potentially problematic down the line. Wh ...

What is the process for changing a JavaScript date to the Hijri format?

Greetings! I am currently working on a web application using AngularJS/JavaScript. In my project, I have implemented a date picker and I am capturing dates from the front end. My goal is to save the selected date in the database in Hijri format. To achieve ...

Tips for developing a nested array of objects using a JavaScript loop

Can someone help me with looping an AJAX response to create an array in this format? "2023-03-30": {"number": '', "url": ""}, "2023-03-30": {"number": '', "url": &quo ...

Just starting out with jQuery: seeking advice on a user-friendly slideshow plugin, any tips on troubleshooting?

I am currently trying to incorporate a basic jquery slideshow plugin, but I seem to be encountering some difficulties. The documentation mentions the need to install 'grunt' and 'node dependencies', which is confusing to me as I am new ...