Using v-bind:ref or just :ref.
Follow below a simple example including how to access a dynamic ref
<template>
<div>
<div class="inputs" v-for="input in inputs" :key="input.id">
<input type="text" v-model="input.name" :ref="'name' + input.id">
<button @click="displayRef('name' + input.id)">
Click to see the input ref
</button>
<hr>
<button @click="displayAllRefs">Click to see all refs</button>
</div>
</div>
</template>
And the script:
<script>
export default {
data() {
return {
inputs: [
{ id: Date.now(), name: '', lastName: '' }
]
}
},
methods: {
displayRef(ref) {
console.log(this.$refs[ref]) // <= accessing the dynamic ref
console.log('The value of input is:',this.$refs[ref][0].value) //<= outpouting value of input
},
displayAllRefs() {
console.log(this.$refs)
}
}
}
</script>