From 08e0089eea1e851eeb15bd6fe59f1799e53733f3 Mon Sep 17 00:00:00 2001 From: yutent Date: Mon, 20 Nov 2023 19:01:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96link=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/form/link.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/form/link.js b/src/form/link.js index 59cdbae..4ceaed3 100644 --- a/src/form/link.js +++ b/src/form/link.js @@ -4,7 +4,7 @@ * @date 2023/03/16 17:40:50 */ -import { css, html, Component, bind, unbind, nextTick } from 'wkit' +import { css, html, Component, bind, nextTick } from 'wkit' class Link extends Component { static props = { @@ -106,6 +106,11 @@ class Link extends Component { ` ] + #stop(ev) { + ev.preventDefault() + ev.stopPropagation() + } + mounted() { this.stamp = 0 @@ -113,7 +118,7 @@ class Link extends Component { nextTick(_ => this.$refs.a.focus()) } - this._clickFn = bind( + bind( this.$refs.a, 'click', ev => { @@ -122,15 +127,11 @@ class Link extends Component { // 除了事件冒泡之外, a标签的默认事件也要阻止 if (disabled) { - ev.preventDefault() - ev.stopPropagation() - return + return this.#stop(ev) } // 并发拦截 if (lazy > 0 && now - this.stamp < lazy) { - ev.preventDefault() - ev.stopPropagation() - return + return this.#stop(ev) } this.stamp = now }, @@ -141,7 +142,7 @@ class Link extends Component { render() { return html` - + ` }