当前位置:网站首页>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"
/>
边栏推荐
猜你喜欢
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
JTAG principle of arm bare board debugging
Gazebo的安装&与ROS的连接
云呐|工单管理软件,工单管理软件APP
Make Jar, Not War
Body mass index program, entry to write dead applet project
Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period
Transplant DAC chip mcp4725 to nuc980
HMM 笔记
Instructions for using the domain analysis tool bloodhound
随机推荐
Taro2.* 小程序配置分享微信朋友圈
Add the applet "lazycodeloading": "requiredcomponents" in taro,
7.6模拟赛总结
LeetCode:1175. 质数排列
Gnet: notes on the use of a lightweight and high-performance go network framework
taro3.*中使用 dva 入门级别的哦
docker 方法安装mysql
Receive user input, height BMI, BMI detection small business entry case
从底层结构开始学习FPGA----FIFO IP的定制与测试
Yunna | work order management measures, how to carry out work order management
负载均衡性能参数如何测评?
交叉验证如何防止过拟合
Taro applet enables wxml code compression
修改px4飞控的系统时间
剑指 Offer II 035. 最小时间差-快速排序加数据转换
拖拽改变顺序
AI 从代码中自动生成注释文档
【C语言进阶篇】指针的8道笔试题
C语言实例_3
Installation of gazebo & connection with ROS