popover中有input
但是在点击触发popover时,input未获取到焦点
需要手动点击才能输入,效果如图
影响用户体验, 需要改进一下
首先想到的方法是 给el-input 添加ref,获取后调用focus()
1 2 3 4 5 6 7 | <el-input placeholder="请输入内容" v-model="value" clearable @keyup.enter.native="confirm" ref="sInput" > |
1 | this.$refs.sInput.focus() |
但是不生效。
查阅资料后发现 需要在popover的show event中手动给el-input获取焦点
1 2 3 4 5 6 7 8 9 | <el-popover placement="bottom" width="200" trigger="manual" v-model="visible" @show="showPopover"> <el-input placeholder="请输入内容" v-model="value" clearable @keyup.enter.native="confirm" ref="sInput" > </el-popover> |
1 2 3 4 5 6 | methods: {<!-- --> showPopover () {<!-- --> this.$nextTick(() => {<!-- --> this.$refs.sInput.focus() }) }, |
这样就完成了,功能实现