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

How to change element hint dynamically with Vuetify 3?

This is my component.vue:

<template>
  <v-text-field
      name="Foo"
      :label="$t('foo')"
      type="text"
      hint="This is a hint"
      persistent-hint
  ></v-text-field>
  <v-btn color="primary" @click="onButtonClick()">Press</v-btn>
 </template>

And this is component.ts

import { defineComponent, reactive, ref, Ref} from 'vue';
export default defineComponent({

  setup() {
     
    function onButtonClick() {
      
    }    
    return { onButtonClick }
  }
});

I want to change hint on button click, for example to This is a new hint. Could anyone say how to do in Vuetify 3 using Composition API?

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

>Solution :

Just create a ref property called hint inside the setup hook then bind it to the hint prop and update it when you click on the button:

import { defineComponent, reactive, ref, Ref} from 'vue';
export default defineComponent({

  setup() {
     const hint=ref('This is a hint')

    function onButtonClick() {
      hint.value="new hint"
    }    
    return { onButtonClick, hint }
  }
});

in template :


<template>
  <v-text-field
      name="Foo"
      :label="$t('foo')"
      type="text"
      :hint="hint"
      persistent-hint
  ></v-text-field>
  <v-btn color="primary" @click="onButtonClick()">Press</v-btn>
 </template>
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