Vue.js Vue材质开关主题(类型';Vue上不存在属性';材质')

Vue.js Vue材质开关主题(类型';Vue上不存在属性';材质'),vue.js,themes,vue-material,Vue.js,Themes,Vue Material,我有一个工作副本,用于在vue typescript和vue material中创建和加载主题 看起来像: SCSS代码: @import "~vue-material/dist/theme/engine"; // Import the theme engine @include md-register-theme("default", ( primary: md-get-palette-color( lime, A200), // The prim

我有一个工作副本,用于在vue typescript和vue material中创建和加载主题

看起来像:

SCSS代码:

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

@include md-register-theme("default", (
  primary: md-get-palette-color( lime, A200), // The primary color of your application
  accent: md-get-palette-color(green, 500), // The accent or secondary color
  secondary: #a10b4a,
  raised: #000000,
  theme: light
));

@import "~vue-material/dist/theme/all"; // Apply the theme
在app.vue中,我只需要这一行:

  import './styles/style.scss'
现在我需要方法切换到另一个主题

在这个环节上没有基本的例子

这一承诺:

错误日志:

16 16 Property 'material' does not exist on type 'Vue'.
    85 | 
    86 |     switchMyTheme = () => {
  > 87 |       this.$root.material.setCurrentTheme('myDark')
    85 | 
    86 |     switchMyTheme = () => {
  > 87 |       this.$root.material.setCurrentTheme('myDark')

有什么建议吗?

您可以使用App.vue中的以下内容在代码中切换主题,例如:

this.$material.theming.theme="differentTheme" //name of your theme
在应用主题之前,只需在导入引擎en之间添加一个新主题:


很好,我只需要放置一个站
(这个。$root作为任何一个)。$material.theming.theme==“myDark”
来修复typescript编译器警告日志。。。
@import "~vue-material/dist/theme/engine";

//Add here after import like:
@include md-register-theme("differentTheme", (
  primary: blue, 
  accent: red
));

//before applying
@import "~vue-material/dist/theme/all"; // Apply the theme