0👍
✅
Solution:
new Vue({
el: '#container',
data: {
},
methods: {
enter(){
//old
//console.log($('[name=' + document.activeElement.name + ']').index())
//new
var active = $('[name=' + document.activeElement.name + ']')
console.log(active.closest('#container').find('input').index(active))
}
}
})
input{display: inline-block;}
span{color: grey;font-size: 10px;display: block;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="container">
<form method="POST" @keyup.enter.prevent="enter">
<input type="text" placeholder="name"><span>expected input 0</span>
<input type="email" placeholder="email">
<span>expected input 1</span>
<input type="password" placeholder="pass">
<span>expected input 2</span>
</form>
</div>
Source:stackexchange.com