2019-06-05 vue $nextTick

    <button ref="btn">我是按钮

    <input type="text" v-show="isShow" ref="input">

export default {

name:'index',

  data () {

return {

isShow:false

    }

},

  mounted () {

this.isShow =true

    // this.$refs.input.focus()

    console.log(this.$refs.input)

// $nextTick  是在DOM更新循环结束之后执行的延迟回调,在修改数据之后使用 $nextTick可以在回调中获取更新后的DOM

    this.$nextTick(() => {

// 更新之后的DOM

this.$refs.input.focus()

})

}

}

<style scoped>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。