Clicking on "span class="before-click" should hide it,
and display input class="after-click" instead.
The displayed input must be in focus!
However, when trying to use $refs.afterClick to access the DOM and apply .focus(),
an unexpected error stating that .focus() is not a function occurs.
How can this issue be resolved?
Thank you.
var myApp = new Vue({
el: '#app',
data: {
onEdit: false,
msg: 'Something in here',
},
methods: {
switchAndFocus() {
if(!this.onEdit) {
this.onEdit = true;
this.$refs.afterClick.focus();
}
},
},
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.3/vue.min.js"></script>
<div id="app">
<span class="before-click" @click="switchAndFocus()" v-show="!onEdit">{{msg}}</span>
<input type="text" class="after-click" ref="afterClick" :value="msg" v-show="onEdit">
</div>