Vuetify's autofocus works only on first modal open

后端 未结 2 1617
情深已故
情深已故 2021-01-01 17:58

I am trying to use Vuetify\'s v-text-field autofocus however it works only first time. After I close the dialog, it doesn\'t work anymore.

相关标签:
2条回答
  • 2021-01-01 18:43

    In your sandbox (but also seems to be the case in your question) you had an error in your code, you removed return from the provided workaround:

    watch: {
      dialog (val) {
        if (!val) return; // you removed `return` here
        requestAnimationFrame(() => {
          return this.$refs.focus.focus();
        }
      });
    

    So actually it works

    0 讨论(0)
  • 2021-01-01 18:47

    The only thing that worked for me was the v-if="dialog" because the autofocus prop will only work on initial load which is why it was available only for the first time I opened the dialog.

    So the working v-tex-field with autofocus in dialog would look something like this:

    <v-text-field label="Label" v-if="dialog" autofocus></v-text-field>
    
    0 讨论(0)
提交回复
热议问题