在vue项目中,点击按钮,获取input输入框中的 焦点
nextTick:
1.语法:this.$nextTick(回调函数)
2.作用:在下一次DOM更新结束后执行其指定的回调
3.什么时候用:在改变数据后,要基于更新后的新的DOM进行某些操作时,要在nextTick所制定的回调函数中执行
代码如下:
html中的代码
<input
type="text"
class="compile"
v-show="qwe.isEdit"
@blur="handelBlur(qwe, $event)"
:id="qwe.id"
ref="inputVal"
v-model="qwe.title" /> input输入框
<button
class="btn edit"
v-show="qwe.isEdit == false"
@click="handelEdit(qwe, $event)"
>
编辑
</button>按钮
js代码
// 编辑
handelEdit(qwe, e) {
if (qwe.hasOwnProperty("isEdit")) {
qwe.isEdit = true;
} else {
this.$set(qwe, "isEdit", true);
}
this.$nextTick(function(){
this.$refs.inputVal.focus()
})
},
如果 nextTick不知道是怎么使用的 , 可以看一下上面的 的解析