博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
点击elementUI中的popover组件,让组件里的input二次获取焦点有效的两种情况
阅读量:4358 次
发布时间:2019-06-07

本文共 2363 字,大约阅读时间需要 7 分钟。

在使用elementUI时,点击table组件中的某个单元格,会弹出一个popover,并且popover中包含input输入框,如果只是给input添加autofocus属性是没有效果的。当然这里也是分两种情况。

第一:点击table组件中的一个单元格,弹出一个popover。

HTML代码:(equipment项目,orderList页面)

1 
6
36

js代码

// 打开修改预设值的弹出框    showAssumptiondsPopover (matchUniqueId) {      this.editAssumption = ''      this.hoverData.map((item, index) => {        this.$set(item, 'assumptionFlag', false)        if (item.matchUniqueId === matchUniqueId) {          this.$set(item, 'assumptionFlag', true)          this.keyAssumptionFalg = true          this.AssumptionIndex = index        }      })      this.$nextTick(() => {        this.$refs.focusAssumptionInput.focus()      })

说明:使用原生属性autofocus 只在模板加载完成时起作用,也就是说只有第一次有用。而使用element UI的组件是通过v-show控制的,所以通过将input输入框的显示控制跟popover组件的显示一致,就能解决了。当然,同时还需要通过Vue中的$nextTick方法,等元素渲染完成后执行该回调方法,这样子focus才有效果。

 

 

 

这里生成的唯一popover方法暂时不讲,下次再说。

第二:table中的单元格中有多个按钮,遍历生成popover。

HTML代码:

js代码:

1 // 打开修改赔率的弹出框 2     showOddsPopover (rows, odds, editIndex) { 3       this.editOdds = '' 4       let len = 0 5       this.hoverData.map((item, index) => { 6         len += item.betItemsObj.length 7         item.betItemsObj.map((item1, index1) => { 8           this.$set(item1, 'flag', false) 9           // 展开对应赔率修改框10           if (item.matchUniqueId === rows.matchUniqueId && (index1 === editIndex) && (item1.odds === odds)) {11             this.$set(item1, 'flag', true)12             this.keyOddFalg = true13             this.oddIndex = index14             this.oddIndexNum = index115           }16         })17       })18       // 赔率输入框获取焦点19       for (let i = 0; i < len; i++) {20         this.$nextTick(() => {21           this.$refs.focusOddsInput[i].focus()22         })23       }24     }

 

转载于:https://www.cnblogs.com/ChelFannie/p/9583800.html

你可能感兴趣的文章
emmet使用技巧
查看>>
RPC-Thrift(二)
查看>>
MSSQL for Linux 安装指南
查看>>
【Golang 接口自动化08】使用标准库httptest完成HTTP请求的Mock测试
查看>>
洛谷 P1036 选数
查看>>
女性社区TOP10
查看>>
BP神经网络算法推导及代码实现笔记zz
查看>>
前端必读:浏览器内部工作原理
查看>>
每天一个Linux命令(16)--which命令
查看>>
libevent文档学习(一)多线程接口和使用
查看>>
【补hackbar的坑】关于hackbar需要钱的补救措施
查看>>
纤程与Quasar
查看>>
MySQL的一个麻烦事
查看>>
Uri、URL和URN三者的区别
查看>>
数据字典的转换
查看>>
二维数组按照指定的字段排序的函数
查看>>
在IAR下通过Jlink将程序直接下载到Flash指定地址
查看>>
POJ2560-雀斑(Freckles)【图论,并查集,最小生成树,KURUSKAL】
查看>>
[Angular] Tree shakable provider
查看>>
[Vue + TS] Use Dependency Injection in Vue Using @Inject and @Provide Decorators with TypeScript
查看>>