如何更改Vue材质主题的颜色

时间:2018-06-08 19:50:20

标签: vue.js sass vue-material

我使用Vue Material默认 - 黑暗主题,将以下内容添加到我的index.js文件中...

// 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');

这很好但现在我想改变主题的颜色。为此,我在模板中添加了以下内容......

// viewport/Viewport.vue

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

并在Viewport.scss中(根据文档)...

# 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";

但是当我构建颜色时,并没有像我期望的那样改变。我看到元素被标记为主要元素,但它仍然显示为蓝色。

enter image description here

我错过了什么?

2 个答案:

答案 0 :(得分:2)

我明白了......

  1. 删除了导入
  2. 更新了以下内容......

    @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";
    

答案 1 :(得分:0)

您的主要组件是什么样的?

你是否在vue-material组件的某处使用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>

或者您只需将其添加到以下部分:

<md-content md-theme="default-dark">