If you want to create a custom command using the directives
attribute, you can focus on an element based on your data binding state (such as box1/box2).
To explore this further, check out Vue Focus.
var demo = new Vue({
el: '#demo',
data: {
box1: true,
box2: false
},
methods: {
changeFocus() {
this.box1 = false;
this.box2 = true;
}
},
directives: {
focus: {
update: function (el, {value}) {
if (value) {
el.focus()
}
}
}
},
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script>
<html>
<body>
<div id="demo">
<input type="text" placeholder="box1" v-focus="box1" @blur="box1 = false"><br>
<input type="text" placeholder="box2" v-focus="box2" @blur="box2 = false"><br>
<button @click="changeFocus()">Change Focus</button>
</div>
</body>
</html>