Hi anyone gives me some ideas to use the parameters as key in function?
for example, i am using vue, and have set html
<div id="app">
<input ref="name" />
<button @click="focusIt('name')">
Click me
</button>
</div>
and javascript code
new Vue({
el: "#app",
methods: {
focusIt(value) {
this.$refs.name.focus();
}
}
})
I have passed name
as a parameter in the focusIt
function, is there any way to use it inside the function as a key? something like this.$refs.name.focus()
?
I have made a jsfiddle
Thanks for any advice!
Update:
I tried the this.$refs[value].focus()
, but it does not work
jsfiddle