How do I change colors on a Vue Material theme
Asked Answered
R

2

7

I am using the Vue Material default-dark theme by adding the following into my index.js file...

// index.js Where the vue instance is instantiated

import 'vue-material/dist/theme/default-dark.css';
...
import Vue from "vue";
...
Vue.use(VueRouter);
const routes = [
    {
        path: '/',
        component: Viewport,
        ...
    }
]
...
window.app.$mount('#jg-app');

This works great but now I want to change the colors on the theme. To do this I added the following to my template...

// viewport/Viewport.vue

<styles src="./Viewport.scss" lang="scss"></styles> 

and in Viewport.scss (per the docs)...

# viewport/Viewport.scss

@import "~vue-material/dist/theme/engine"; // Import the theme engine

@include md-register-theme("default-dark", (
  primary: md-get-palette-color(green, A200), // The primary color of your application
  accent: md-get-palette-color(yellow, A200) // The accent or secondary color
));

@import "~vue-material/dist/theme/all";

But when I build the colors do not change as I would expect. I see that the element is marked as primary but it still shows blue.

enter image description here

What am I missing?

Roxanaroxane answered 8/6, 2018 at 19:50 Comment(1)
Also must be able to be used with webpackRoxanaroxane
R
3

I got it...

  1. Removed the import
  2. Updated sass to the following...

    @import "~vue-material/dist/theme/engine";
    
    @include md-register-theme("default", (
      primary: md-get-palette-color(green, A200), // The primary color of your application
      accent: md-get-palette-color(red, A200), // The accent or secondary color
      theme: dark // This can be dark or light
    ));
    
    @import "~vue-material/dist/theme/all";
    
Roxanaroxane answered 11/6, 2018 at 17:57 Comment(2)
Followed same procedure, but getting this error 'Failed to find '~vue-material/dist/theme/engine''Florey
have you run npm install --save vue-material Also this has been a while so let me know if it isn't working anymoreRoxanaroxane
T
1

What is your main component looking like?

Do you use somewhere in a vue-material component md-theme="default-dark"?

<template>
  <div class="page-container">
    <md-app md-theme="default-dark">
      <md-app-toolbar class="md-primary">
        <span class="md-title">My Title</span>
      </md-app-toolbar>
    ....
    </md-app>
  </div>
</template>

or otherwise you just add it to a part like:

<md-content md-theme="default-dark">
Tagmeme answered 11/6, 2018 at 8:47 Comment(2)
Probably should be a comment and not an answer ;-). I add the theme to my page using import 'vue-material/dist/theme/default-dark.css';Roxanaroxane
Also I don't use md-app I use... window.app.$mount('#jg-app'); & I tried to add md-theme to my root of my route but it didn't work.Roxanaroxane

© 2022 - 2024 — McMap. All rights reserved.