Vuetify's autofocus works only on first modal open

一世执手 提交于 2019-11-30 13:11:34

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>

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!