方法一 这个方法适合vue插件,id比较好绑定
// html 部分
<input type="text" id="name">
// js部分
mounted() {
this.$nextTick(() =>{
document.getElementById('phone').focus();
})
},
方法二 这个如果插件解决不了ref的绑定还是用ID吧
//html 部分
<input type="text" ref="name">
// js 部分
mounted() {
this.$nextTick(() =>{
this.$refs.name.focus()
})
},