vue.js: how to handle click and dblclick events on same element

后端 未结 7 2201
粉色の甜心
粉色の甜心 2021-02-01 16:01

I have a vue component with separate events for click/dblclik. Single click (de)selects row, dblclick opens edit form.

7条回答
  •  迷失自我
    2021-02-01 16:08

    i have a simpler solution i think (i'm using vue-class but same principle apply):

    private timeoutId = null;
    onClick() {
            if(!this.timeoutId)
            {
                this.timeoutId = setTimeout(() => {
                    // simple click
                }, 50);//tolerance in ms
            }else{
                clearTimeout(this.timeoutId);
                // double click
            }
        }
    

    it does not need to count the number of clicks.

提交回复
热议问题