Home  >  Q&A  >  body text

Dynamically change Vuetify 3 themes - step-by-step guide

I want to change the theme dynamically. I defined lightTheme and darkTheme li

export default createVuetify({
  theme: {
    defaultTheme: "lightTheme",
    themes: {
      lightTheme: {
        dark: false,
        colors: {
          primary: "#ad1c3d",
          "page-header-background": "#d7d7ce",
          "page-background": "#cdcdc1",
          "table-header": "#cdcdc1",
          background: "#c0c0b5",
          "header-background": "#b5b5a6",
          "info-text": "#666660",
        },
      },
      darkTheme: {
        dark: true,
        colors: {
          primary: "#52E3C2",
          "page-header-background": "#282831",
          "page-background": "#32323E",
          "table-header": "#2e2e2e",
          background: "#3F3F4A",
          "header-background": "#4a4a59",
          "info-text": "#99999F",
        },
      },
    },
  },
});

I can access the theme using this.$vuetify.theme, but I can't find how to change the theme at runtime. The way to do this is different in Vuetify 2. I can't find any examples of Vuetify 3.

What is the correct way to dynamically change themes in Vuetify 3?

P粉811329034P粉811329034318 days ago553

reply all(1)I'll reply

  • P粉736935587

    P粉7369355872023-12-06 12:57:03

    The documentation seems incorrect. The documentation says to use

    this.theme.global.name.value = "themeName"

    but actually

    this.theme.global.name = "themeName"

    reply
    0
  • Cancelreply