Created
October 15, 2022 13:13
-
-
Save wadez/24b3acd65be171dbb31aa1f43899e725 to your computer and use it in GitHub Desktop.
Vue3 Dynamic Refs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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