当前位置:网站首页>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"
/>
边栏推荐
- 树莓派/arm设备上安装火狐Firefox浏览器
- 从底层结构开始学习FPGA----FIFO IP的定制与测试
- table表格设置圆角
- AcWing 1141. 局域网 题解(kruskalkruskal 求最小生成树)
- shell脚本快速统计项目代码行数
- Metauniverse urban legend 02: metaphor of the number one player
- 剑指 Offer II 035. 最小时间差-快速排序加数据转换
- C语言实例_5
- HMM notes
- Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period
猜你喜欢

Wood extraction in Halcon

Let's see through the network i/o model from beginning to end

405 method not allowed appears when the third party jumps to the website

鼠标右键 自定义

Js逆向——捅了【马蜂窝】的ob混淆与加速乐

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

Send template message via wechat official account

Gazebo的安装&与ROS的连接

Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform

黑马笔记---创建不可变集合与Stream流
随机推荐
hdu 4661 Message Passing(木DP&amp;组合数学)
2022 Google CTF SEGFAULT LABYRINTH wp
MySQL script batch queries all tables containing specified field types in the database
Receive user input, height BMI, BMI detection small business entry case
【芯片方案设计】脉搏血氧仪
Neon Optimization: an instruction optimization case of matrix transpose
【C语言进阶篇】指针的8道笔试题
736. Lisp 语法解析 : DFS 模拟题
C language instance_ three
图片打水印 缩放 和一个输入流的转换
鼠标右键 自定义
LeetCode:1175. 质数排列
AcWing 344. 观光之旅题解(floyd求无向图的最小环问题)
AcWing 1141. 局域网 题解(kruskalkruskal 求最小生成树)
The cost of returning tables in MySQL
Neon Optimization: an optimization case of log10 function
What does security capability mean? What are the protection capabilities of different levels of ISO?
736. LISP syntax parsing: DFS simulation questions
树莓派/arm设备上安装火狐Firefox浏览器
Transplant DAC chip mcp4725 to nuc980