当前位置:网站首页>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)
边栏推荐
猜你喜欢

专利检索常用的网站有哪些?

第56章 业务逻辑之物流/配送实体定义
![[Multi-task model] Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized (RecSys'20)](/img/7d/f8f150ad13f4cacc143491fcd8420b.png)
[Multi-task model] Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized (RecSys'20)

环境变量,进程地址空间

MySQL你到底都加了什么锁?

Intranet penetration lanproxy deployment

部署zabbix

【多任务学习】Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts KDD18

SIPp installation and use

【Untitled】
随机推荐
【节能学院】推进农业水价综合改革的意见解读
有用的网站
【多任务模型】Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized(RecSys‘20)
Compose实战-实现一个带下拉加载更多功能的LazyColumn
Redis does web page UV statistics
图文详述Eureka的缓存机制/三级缓存
Wildcard SSL/TLS certificate
Zheng Xiangling, Chairman of Tide Pharmaceuticals, won the "2022 Outstanding Influential Entrepreneur Award" Tide Pharmaceuticals won the "Corporate Social Responsibility Model Award"
把 Oracle 数据库从 RAC 集群迁移到单机环境
Interpretation of the meaning of each dimension of two-dimensional, three-dimensional, and four-dimensional matrices
CMake教程——Leeds_Garden
二维、三维、四维矩阵每个维度含义解释
Greenplum Database Source Code Analysis - Analysis of Standby Master Operation Tools
瀚高数据导入
环境变量,进程地址空间
openresty 动态黑白名单
[Multi-task optimization] DWA, DTP, Gradnorm (CVPR 2019, ECCV 2018, ICML 2018)
【无标题】
作为程序员你应该会的软件
漏刻有时文档系统之XE培训系统二次开发配置手册