<template></template> <script> export default { data: () => ({ timeout: null, delay: 1000,//长按1秒 }), created() { addEventListener('mousedown', this.mousedown); addEventListener('click', this.click); }, methods: { mousedown(e) { this.timeout = setTimeout(() => { this.timeout = null; console.log(`长按`); }, this.delay); }, click(e) { if (this.timeout) { clearTimeout(this.timeout), (this.timeout = null); console.log(`单击`); } }, } }; </script>