Answer the question
In order to leave comments, you need to log in
How to get all inputs from ref in Vue3?
Hello!
Tell me how to get an array of inputs?
now in the onFocus function it displays only the last input, the rest he does not see
where he screwed up? Thank you
<template>
<div>
<div :class="$style.inputVerify">
<input
v-for="(v, index) in values"
ref="inputRefs"
:key="index"
type="number"
required="true"
pattern="[0-9]"
maxlength="1"
:class="$style.inputVerifyItem"
:autoFocus="index === autoFocusIndex"
:data-id="index"
:value="v"
@input="onValueChange"
@click="onFocus"
@keydown="keyPres"
/>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent, ref } from "vue";
export default defineComponent({
props: {
fields: {
type: Number,
default: 4,
},
timerSeconds: {
type: Number,
default: 20,
},
},
setup(props, { emit }) {
const autoFocusIndex = ref(0);
const values = ref<any[]>([]);
const inputRefs = ref<any>([]);
const fields = ref(props.fields) as any;
const seconds = ref(props.timerSeconds) as any;
const timerInterval = ref() as any;
for (let i = 0; i < fields.value; i++) {
values.value.push("");
}
const onFocus = (e: any) => {
const index = parseInt(e.target.getAttribute("data-id"));
console.log(index)
inputRefs.value[index] = "";
values.value[index] = "";
if (!values.value[index] && index !== 0) {
console.log(inputRefs.value)
}
};
return {
onFocus,
};
},
});
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question