当前位置:网站首页>Custom command to get focus
Custom command to get focus
2022-08-01 20:03:00 【kilito_01】
// 对Vue的全局指令, 进行封装
// 封装中间件函数插件
const directiveObj = {
install (Vue) {
Vue.directive('focus', {
// elRepresents the label where the command is located
// 指令所在标签, is inserted into the realDOM时才触发, If the label is useddisplay:nonehide and reappear, 不会在触发inserted的
inserted (el) {
// 指令所在van-search组件
// 组件根标签是div, input在内部
// 以上都是原生标签对象
// 搜索页面 el是div
// 文章评论 el是textarea
// 以后el还可能是input呢
// 知识点: 原生DOM.nodeName Get the tag name (注意: 大写的字符串)
if (el.nodeName === 'TEXTAREA' || el.nodeName === 'INPUT') {
el.focus()
} else {
// elNot an input box by itself, Try to get it in there
setTimeout(() => {
const theInput = el.querySelector('input')
const theTextArea = el.querySelector('textarea')
// 判断: Not necessarily obtainable, 需要加判断, 有值了, 再执行.focus()才不报错
if (theInput) theInput.focus()
if (theTextArea) theTextArea.focus()
})
}
},
update (el) {
// 指令所在标签, 被更新时触发
if (el.nodeName === 'TEXTAREA' || el.nodeName === 'INPUT') {
el.focus()
} else {
// elNot an input box by itself, Try to get it in there
setTimeout(() => {
const theInput = el.querySelector('input')
const theTextArea = el.querySelector('textarea')
// 判断: Not necessarily obtainable, 需要加判断, 有值了, 再执行.focus()才不报错
if (theInput) theInput.focus()
if (theTextArea) theTextArea.focus()
})
}
}
})
}
}
export default directiveObj
在main.jsJust register globally
import directiveObj from ‘./utils/directive’
Vue.use(directiveObj)
边栏推荐
- 多线程之生产者与消费者
- 锐捷交换机基础配置
- 专利检索常用的网站有哪些?
- Redis 做网页UV统计
- 卷积神经网络(CNN)mnist数字识别-Tensorflow
- 根据Uniprot ID/PDB ID批处理获取蛋白质.pdb文件
- [Energy Conservation Institute] Comparative analysis of smart small busbar and column head cabinet solutions in data room
- Pytorch模型训练实用教程学习笔记:一、数据加载和transforms方法总结
- 第60章 ApplicationPart自动集成整体性和独立性插件项
- Greenplum数据库源码分析——Standby Master操作工具分析
猜你喜欢

数字孪生北京故宫,元宇宙推进旅游业进程

终于有人把AB实验讲明白了

【节能学院】数据机房中智能小母线与列头柜方案的对比分析

【七夕特别篇】七夕已至,让爱闪耀

第58章 结构、纪录与类

】 【 nn. The Parameter () to generate and why do you want to initialize

第55章 业务逻辑之订单、支付实体定义

The graphic details Eureka's caching mechanism/level 3 cache

Win10, the middle mouse button cannot zoom in and out in proe/creo

【无标题】
随机推荐
通配符 SSL/TLS 证书
我的驾照考试笔记(2)
GEE(8):使用MODIS填补由去云后的Landsat影像计算得到的NDVI数据
把 Oracle 数据库从 RAC 集群迁移到单机环境
启明云端分享|盘点ESP8684开发板有哪些功能
我的驾照考试笔记(4)
为什么限制了Oracle的SGA和PGA,OS仍然会用到SWAP?
模板特例化和常用用法
【无标题】
[Multi-task optimization] DWA, DTP, Gradnorm (CVPR 2019, ECCV 2018, ICML 2018)
锐捷交换机基础配置
Intranet penetration lanproxy deployment
解除360对默认浏览器的检测与修改
安全作业7.25
洛谷 P2440 木材加工
openresty 动态黑白名单
How PROE/Croe edits a completed sketch and brings it back to sketching state
第55章 业务逻辑之订单、支付实体定义
【七夕特别篇】七夕已至,让爱闪耀
Creo5.0草绘如何绘制正六边形