优化link组件

master
yutent 2023-11-20 19:01:20 +08:00
parent 07901c84fb
commit 08e0089eea
1 changed files with 10 additions and 9 deletions

View File

@ -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`
<a tabindex="0" ref="a" class="link" href=${this.to || 'javascript:;'}>
<slot />
<slot></slot>
</a>
`
}