Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JavaScript.. Use values of local variables in other functions

I’ve been searching for days to solve this problem…

enter image description here

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

As shown in the image above,
I need to apply the data values from other places to the Vuetify Primary
I’ve been googling over and over again, but I can’t find the answer…
Can you tell me the answer?

This is the JavaScript in question

const primaryColor = variablecolor

export function setColor(variablecolor) {
  console.log('colorCheck',variablecolor)
}

export default createVuetify({
  theme: {
    themes: {
      light: {
        colors: {
          primary: primaryColor,
          secondary: '#5CBBF6',
        },
      },
    },
  },
})

These are the methods that are sent to the JavaScript in question

  methods: {
      updateColor() {
        setColor(this.btn_color)
      },
    }

>Solution :

You can’t dynamically update the initial theme object used by createVuetify but you can instead have your updateColor() method directly modify $vuetify.theme where the theme colors are made accessible as noted in the documentation

values will also be made available on the instance $vuetify object under the theme property. This allows you to dynamically modify your theme. Behind the scenes, Vuetify will regenerate and update your theme classes, seamlessly updating your application.

// Light theme

this.$vuetify.theme.themes.light.primary = ‘#4caf50’

// Dark theme

this.$vuetify.theme.themes.dark.primary = ‘#4caf50’

In your case, the method would look something like this:

updateColor() {
  this.$vuetify.theme.themes.light.primary = this.btn_color
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading