Iview: Modal多次打开关闭,input无法获取焦点

Created on 4 Jun 2017  ·  3Comments  ·  Source: iview/iview



iView 版本号

2.0.0-rc.14

操作系统/浏览器 版本号

macOS

Vue 版本号

2.2.6

能够复现问题的在线示例(bug 相关不提供在线示例将直接 close)

https://jsfiddle.net/LittleChild/34jr8q87/

复现步骤

第一次点击input可以自动获取焦点,第二次点击后就无法获取焦点。

问题现象,以及你期望的结果是怎样的?

希望可以多次打开modal,input框都可以自动获取焦点。

你估计可能的原因是什么(选填)?

是否只是dom的显示和隐藏并不是重新渲染,所以只能获取一次焦点?能否给一些建议,谢谢。

Most helpful comment

使用 autofocus,input 只有在第一次加载时才会自动获取焦点。第二次点击时并未重新加载,所以未自动获取。如果想要多次点击均自动获取,可以考虑手动调用 input 标签的 focus() 方法。

<i-input ref="input" autofocus></i-input>
open() {
    this.codeDialogIsShow = true
    this.$nextTick(() => {
        this.$refs.input.focus()
    })
}

希望能帮到你。

All 3 comments

使用 autofocus,input 只有在第一次加载时才会自动获取焦点。第二次点击时并未重新加载,所以未自动获取。如果想要多次点击均自动获取,可以考虑手动调用 input 标签的 focus() 方法。

<i-input ref="input" autofocus></i-input>
open() {
    this.codeDialogIsShow = true
    this.$nextTick(() => {
        this.$refs.input.focus()
    })
}

希望能帮到你。

用您说这种直接操作dom的方式解决了,谢谢。

dinglei9592的方法有效,多谢了!!!

Was this page helpful?
0 / 5 - 0 ratings