当前位置:网站首页>Double click events and click events
Double click events and click events
2022-06-29 02:43:00 【Red blue purple】
Double click events and click events
Preface
When the project encounters a double-click event, the click event will be triggered at the same time bug, Or simply record .
one's innermost thoughts and feelings : I am even more tired today . I used to spend several days alone reading other people's blogs , Read many blogs and then output them slowly . Now it's input and output ( Sometimes a long article is split into two parts in order to be lazy ), After collecting the wool of this full service , After that, I took part in more activities on the day ( Go on like this , I feel that the original intention of blogging is about to change )
Problem recurrence
<el-button type="primary" @click="myclick" @dblclick="mydblclick">
test
</el-button>
function myclick() {
console.warn(" Click events ");
}
function mydblclick() {
console.error(" Double-click the event ");
}

be perfectly logical and reasonable , Double click events are also double click events , So the click event will be triggered at the same time click And double click events dblclick. But the requirement is to click and double-click different processing , Therefore, the click event should not be triggered when double clicking .
Solution
Ideas : You can use the function anti shake method , Click after the event is triggered , Turn on a timer , Double click the event trigger to clear the timer .
let timer;
function myclick() {
timer = setTimeout(() => {
console.warn(" Click events ");
}, 300);
}
function mydblclick() {
clearTimeout(timer);
console.error(" Double-click the event ");
}

It can be found that there are still problems , A double-click event will still trigger a single click event .
But this problem is actually a problem with the use of timers . Let's take a look at a small case .
let timer;
timer = setTimeout(() => {
console.log(1);
});
timer = setTimeout(() => {
console.log(2);
});
clearTimeout(timer);
In this case , prints 1. In other words, only the second timer is actually clear , So our previous code needs to clear the first timer .
let timer;
function myclick() {
clearTimeout(timer);
timer = setTimeout(() => {
console.warn(" Click events ");
}, 300);
}
function mydblclick() {
clearTimeout(timer);
console.error(" Double-click the event ");
}
Be accomplished .
el-checkbox Use caution
The problem of double click event and click event is solved , Plus the next project's stepping on the pit .
el-checkbox No event objects , Common event objects are el-checkbox Upper is Boolean , Indicates whether to select . But there are native versions .
<el-checkbox @change="mychange"></el-checkbox>
<input type="checkbox" @click="mychange" />
function mychange(e) {
console.log(e);
}

in addition , Directly modifying checkbox The value of the binding , Not trigger change event .
change Event directly modifying the value will not trigger .
<input type="checkbox" v-model="checked" @click="mychange" />
<button @click="myclick">change</button>
import { ref } from "@vue/reactivity";
const checked = ref(true);
function mychange(e) {
console.log(e);
}
function myclick() {
checked.value = !checked.value;
}

You can modify the binding value directly while , Manual call change Event handler to simulate triggering change event , however , The parameter passing of the event object is not easy to simulate . Of course , If you are using el-checkbox Words , Because it has no event object , It's a Boolean , So just put checkbox The value of the current binding can be passed .
边栏推荐
- PWN attack and defense world guess_ num
- 矩阵特征值和特征向量求解——特征值分解(EVD)
- China's flexible employment has reached 200million
- 兰宝传感科技冲刺科创板:年营收3.5亿 许永童家族色彩浓厚
- CTFHub-Web-密码口令-弱口令
- Table implements alternative adaptation through pseudo classes
- PWN攻防世界Level2
- The 10 most commonly used gadgets for waterfall project management can be built and used freely
- String segment combination
- Understanding and design of high concurrency
猜你喜欢

【无标题】

sql训练01
![[untitled]](/img/36/2f9319e05157ab6a8dd5aa3bef4505.png)
[untitled]

Understanding and design of high concurrency

Pvcreate ASM disk causes abnormal recovery of ASM disk group - sparing separation

Programmers whose monthly salary is less than 30K must recite the interview stereotype. I'll eat it first

兰宝传感科技冲刺科创板:年营收3.5亿 许永童家族色彩浓厚

CTFHub-Web-SQL注入-整数型注入

Wechat applet custom component

Overview of PMP project management
随机推荐
PWN beginner level0
[sans titre]
音响是如何把微弱声音放大呢
matlab习题 —— 图像绘制练习
apache不解析PHP文件,直接显示源码
解决allegro中测量距离时,点击一个点后光标闪烁的问题
CTFHub-Web-密码口令-弱口令
Mipi d-phy -- contents of HS and LP agreements
Oracle recovery tools actual batch bad block repair
Today's sleep quality record 82 points
信息学奥赛一本通 1361:产生数(Produce)
What is a thread pool?
Introduction to openresty
String length
Trigonometric function calculation
Talk about SQL optimization
2022年启牛学堂证券开户安全的嘛?
allegro设置网络飞线以及网络颜色的方法
[線性代數] 1.1 二階與三階行列式
SQL training 01