下面是一个自定义指令的例子,当一个 input 元素被 Vue 插入到 DOM 中后,它会被自动聚焦。

解决方案:在input标签里增加ref属性,然后在export default 中增加构子函数mounted (挂载完成),写入以下代码,表示页面渲染完成后光标定位输入框。

mounted(){
        this.$nextTick(() =>{
            this.$refs.inputName.focus()
        })
    }

 

 

posted on 2023-04-11 14:19  给天使看的戲  阅读(65)  评论(0编辑  收藏  举报