Can someone suggest ways to utilize parameters as keys in a function?
For example, I am using Vue and have the following HTML setup:
<div id="app">
<input ref="name" />
<button @click="focusIt('name')">
Click me
</button>
</div>
Accompanied by this JavaScript code:
new Vue({
el: "#app",
methods: {
focusIt(value) {
this.$refs.name.focus();
}
}
})
Is there a way to use the parameter passed in the focusIt
function as a key inside the function like this.$refs.name.focus()
?
I created a jsfiddle for reference.
Thank you for any guidance!
Update:
I attempted to use this.$refs[value].focus()
, but it did not work.
Here is the updated jsfiddle