方法一:使用自定义事件
<script>
export default{
data(){
return{
}
},
directives: {
focus: {
// 指令的定义
inserted: function (el) {
el.focus()
}
},
color:{
inserted(el,bind){
el.style.color = bind.value
}
}
}
}
</script>
方法二:使用js方法直接focus()
<input type="text" class="search-content" v-model="key" ref="content">
mounted:function () {
var self = this;
self.keyBorad();
this.$nextTick(() => {
self.$refs.content.focus();
})
},
注意:但是上述两种方法在苹果手机都不能获取焦点!!!暂未找到解决方法。