当前位置:网站首页>Long press the button to execute the function
Long press the button to execute the function
2022-07-07 01:35:00 【Ah Liu】
stay utils Create under folder longPress.ts
import {
DirectiveOptions } from 'vue';
const longPress: DirectiveOptions = {
// bind: Call it once , The first time an instruction is bound to an element
// el: Element bound by instruction , Can be used for direct operation DOM.
// binding: An object . name: Instruction name ,value: Binding value of instruction
// vnode: Compile generated virtual nodes
bind: function (el, binding, vNode) {
// el Namely dom
if (typeof binding.value !== 'function') {
// eslint-disable-next-line
console.log('callback must be a function');
}
// Defining variables
let pressTimer: any = null;
// Operation function
const handler = (e: Event) => {
binding.value(e);
};
// Create timer (1 The function is executed in seconds )
const start = (e: any) => {
if (e.type === 'click') {
return;
}
if (pressTimer === null) {
pressTimer = setTimeout(() => {
handler(e);
}, 1000);
}
};
// Cancel the timer
const cancel = () => {
if (pressTimer !== null) {
clearTimeout(pressTimer);
pressTimer = null;
}
};
// Add event listener
el.addEventListener('mousedown', start);
// Cancel the timer
el.addEventListener('click', cancel);
el.addEventListener('mouseout', cancel);
},
// Triggered when the value passed in is updated
componentUpdated (el: any, {
value }) {
el.$value = value;
},
// When an instruction is unbound to an element , Remove event binding
unbind (el: any) {
el.removeEventListener('click', el.handler);
}
};
export default longPress;
Introduce and use in required documents
introduce
import longpress from '@/utils/longpress';
@Component({
components: {
},
directives: {
longpress
}
})
Use
<basic-button
v-longpress="handleLongMoveLeft"
type="info"
plain
icon="el-icon-arrow-left"
@click="moveLeft"
/>
边栏推荐
- 从零开始匹配vim(0)——vimscript 简介
- Neon Optimization: an optimization case of log10 function
- Spark TPCDS Data Gen
- 2022 Google CTF SEGFAULT LABYRINTH wp
- Realize incremental data synchronization between MySQL and ES
- ZOJ Problem Set – 2563 Long Dominoes 【如压力dp】
- 设置Wordpress伪静态连接(无宝塔)
- Gnet: notes on the use of a lightweight and high-performance go network framework
- 拖拽改变顺序
- 搭建【Redis in CentOS7.x】
猜你喜欢

云呐|工单管理软件,工单管理软件APP

AcWing 361. 观光奶牛 题解(spfa求正环)

go-zero微服务实战系列(九、极致优化秒杀性能)

Let's see how to realize BP neural network in Matlab toolbox

2022 Google CTF segfault Labyrinth WP

Today's question -2022/7/4 modify string reference type variables in lambda body

对C语言数组的再认识

第三方跳转网站 出现 405 Method Not Allowed

454-百度面经1

2022 Google CTF SEGFAULT LABYRINTH wp
随机推荐
黑马笔记---异常处理
Table table setting fillet
THREE.AxesHelper is not a constructor
C语言实例_4
curl 命令
Realize incremental data synchronization between MySQL and ES
C语言实例_3
c语言—数组
编译命令行终端 swift
Yunna - work order management system and process, work order management specification
Body mass index program, entry to write dead applet project
[advanced C language] 8 written questions of pointer
2022 Google CTF SEGFAULT LABYRINTH wp
域分析工具BloodHound的使用说明
【信号与系统】
Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
C语言实例_2
The MySQL database in Alibaba cloud was attacked, and finally the data was found
454-百度面经1
Google发布安全更新,修复Chrome中已被利用的0 day