当前位置:网站首页>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"
/>
边栏推荐
- 对C语言数组的再认识
- Today's question -2022/7/4 modify string reference type variables in lambda body
- Taro2.* applet configuration sharing wechat circle of friends
- AcWing 346. 走廊泼水节 题解(推公式、最小生成树)
- Docker method to install MySQL
- Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
- [signal and system]
- Gnet: notes on the use of a lightweight and high-performance go network framework
- 树莓派/arm设备上安装火狐Firefox浏览器
- 安全保护能力是什么意思?等保不同级别保护能力分别是怎样?
猜你喜欢
Make Jar, Not War
The difference between Tansig and logsig. Why does BP like to use Tansig
1123. 最深叶节点的最近公共祖先
鼠标右键 自定义
移植DAC芯片MCP4725驱动到NUC980
[advanced C language] 8 written questions of pointer
According to the analysis of the Internet industry in 2022, how to choose a suitable position?
Let's see through the network i/o model from beginning to end
tansig和logsig的差异,为什么BP喜欢用tansig
Js逆向——捅了【马蜂窝】的ob混淆与加速乐
随机推荐
[chip scheme design] pulse oximeter
Taro applet enables wxml code compression
树莓派/arm设备上安装火狐Firefox浏览器
Case development of landlord fighting game
编译命令行终端 swift
WCF基金会
How to evaluate load balancing performance parameters?
HMM notes
Add the applet "lazycodeloading": "requiredcomponents" in taro,
[case sharing] basic function configuration of network loop detection
Yunna - work order management system and process, work order management specification
Machine learning: the difference between random gradient descent (SGD) and gradient descent (GD) and code implementation.
Receive user input, height BMI, BMI detection small business entry case
增加 pdf 标题浮窗
POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
安利一波C2工具
Make Jar, Not War
Instructions for using the domain analysis tool bloodhound
swiper组件中使用video导致全屏错位
What does security capability mean? What are the protection capabilities of different levels of ISO?