Skip to content

Instantly share code, notes, and snippets.

@wadez
Created October 15, 2022 13:13
Show Gist options
  • Save wadez/24b3acd65be171dbb31aa1f43899e725 to your computer and use it in GitHub Desktop.
Save wadez/24b3acd65be171dbb31aa1f43899e725 to your computer and use it in GitHub Desktop.
Vue3 Dynamic Refs
<script setup>
import { ref } from 'vue';
const inputs = {
f1: ref(),
f2: ref(),
f3: ref(),
}
function clickMe(refId) {
var input = inputs[refId]?.value
input?.focus()
}
</script>
<template>
<div @click="clickMe('f1')">
<input :ref="inputs.f1" />
<Icon />
</div>
<div @click="clickMe('f2')">
<input :ref="inputs.f2" />
<Icon />
</div>
<div @click="clickMe('f3')">
<input :ref="inputs.f3" />
<Icon />
</div>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment