我们用一个例子来说明$nextTick的作用:
我们用一个变量showIpt来控制input框的显示和隐藏,默认是隐藏。
我们点击一个按钮后显示这个输入框的同时,input还要自动获取焦点。

但是我们点击按钮过后并没有生效。

为什么?this.showIpt=true执行过后接着就是执行this.$refs.ipt.focus() ,所有的代码执行完毕后将解析好的DOM放到页面上去。
也就是说,focus() 的时候DOM还没解析呢!
因此,我们就可以使用$nextTick() 来解决这个问题:
this.$nextTick( // 执行函数 )
$nextTick() 的作用就是在下一次DOM更新结束后执行其指定的回调。
当数据改变后,要对更新后的DOM进行一些操作时,就可以在$nextTick() 的回调函数中执行。

