当前位置:网站首页>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)
边栏推荐
- 用户体验好的Button,在手机上不应该有Hover态
- Redis does check-in statistics
- 58:第五章:开发admin管理服务:11:开发【管理员人脸登录,接口】;(未实测)(使用了阿里AI人脸识别)(演示了,使用RestTemplate实现接口调用接口;)
- KDD2022 | Self-Supervised Hypergraph Transformer Recommendation System
- 【七夕特别篇】七夕已至,让爱闪耀
- XSS range intermediate bypass
- 【多任务学习】Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts KDD18
- 因斯布鲁克大学团队量子计算硬件突破了二进制
- SIPp 安装及使用
- 第56章 业务逻辑之物流/配送实体定义
猜你喜欢
【kali-信息收集】(1.5)系统指纹识别:Nmap、p0f
[Multi-task model] Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized (RecSys'20)
网络不通?服务丢包?这篇 TCP 连接状态详解及故障排查,收好了~
[Personal work] Wireless network image transmission module
XSS range intermediate bypass
八百客、销售易、纷享销客各行其道
使用微信公众号给指定微信用户发送信息
17、负载均衡
专利检索常用的网站有哪些?
第56章 业务逻辑之物流/配送实体定义
随机推荐
17、负载均衡
正则表达式
Creo5.0 rough hexagon is how to draw
datax - 艰难debug路
[Multi-task optimization] DWA, DTP, Gradnorm (CVPR 2019, ECCV 2018, ICML 2018)
9月备考PMP,应该从哪里备考?
大整数相加,相减,相乘,大整数与普通整数的相乘,相除
Arthas 常用命令
Greenplum Database Source Code Analysis - Analysis of Standby Master Operation Tools
Batch get protein .pdb files based on Uniprot ID/PDB ID
30-day question brushing plan (5)
【节能学院】智能操控装置在高压开关柜的应用
KDD2022 | Self-Supervised Hypergraph Transformer Recommendation System
智能硬件开发怎么做?机智云全套自助式开发工具助力高效开发
GEE(8):使用MODIS填补由去云后的Landsat影像计算得到的NDVI数据
如何写一个vim插件?
密码学的基础:X.690和对应的BER CER DER编码
Software you should know as a programmer
使用常见问题解答软件的好处有哪些?
ARTS_202207W2