Replies: 2 comments
-
Try <el-input v-model="optionsFormValues.name" ref="form_name" />
<script setup lang="ts">
import { ref } from 'vue';
const form_name = ref()
function asdf () {
form_name.value.focus()
}
``` |
Beta Was this translation helpful? Give feedback.
0 replies
-
This only happened to me before when using el-input inside of a el-dialog, if it's your case you need to execute the code in the "opened" event because it ensures that the function it's executed before the element (in this case the input) renders and avoid calling a non-existent reference that eventually will give you a error. It should be something like this with the options API: In methods: focus_input() {
this.$refs['form_name'].focus();
} In template: <el-dialog @opened="focus_input" v-model="yourdialogvalue">
<el-input v-model="optionsFormValues.name" ref="form_name"/>
</el-dialog> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I am quite new to VueJS and Element Plus, so, please, forgive me if this is a stupid question or has already been answered. I am creating a dialog, that contains a form. I want to focus an input when the dialog is shown. I have tried using:
And then:
But that doesn't work. I have seen that the component exposes a
ref
attribute, but I couldn't find a way to use it. Any help?Beta Was this translation helpful? Give feedback.
All reactions