Vue -Темы переключения материалов (свойство 'материал' не существует для типа 'Vue) - PullRequest
0 голосов
/ 09 июля 2020

У меня есть рабочая копия для создания и загрузки темы в vue -типскрипте против vue -материала.

Выглядит так:

S CSS код:

@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

В приложении. vue Мне нужна только эта строка:

  import './styles/style.scss'

Теперь мне нужен способ переключения на другую тему.

По этой ссылке https://vuematerial.io/themes/concepts/ no basi c примеры.

Это обещание:

журнал ошибок:

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

Есть предложения?

1 Ответ

1 голос
/ 09 июля 2020

Вы можете переключать темы в коде, используя следующее в приложении. vue, например:

this.$material.theming.theme="differentTheme" //name of your theme

Просто добавьте новую тему между импортированием движка и перед применением темы (ей):

@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
...