优化代码

master
yutent 2023-03-24 17:04:18 +08:00
parent b59ee76ab5
commit 8b38cec1fa
4 changed files with 15 additions and 18 deletions

View File

@ -248,10 +248,6 @@ class Button extends Component {
} }
} }
unmounted() {
this.$off('click', this._clickFn)
}
render() { render() {
return html` return html`
<button ref="btn" disabled=${this.disabled}> <button ref="btn" disabled=${this.disabled}>

View File

@ -1,20 +1,28 @@
import { nextTick, css, html, Component } from '@bd/core' import { nextTick, css, html, Component, bind } from '@bd/core'
class Dropdown extends Component { class Dropdown extends Component {
bar = 'balbal'
mounted() { mounted() {
console.log('Dropdown: ', this.$refs) console.log('Dropdown: ', this.$refs)
bind(this.$refs.balbal, 'mousedown', ev => {
console.log('aa : mousedown')
})
} }
foo() {} foo() {
console.log('foo: click')
}
render() { render() {
return html` return html`
<div class="aa" ref="aa" @click=${this.foo}> <div class="aa" ref=${this.bar} @click=${this.foo}>
<div class="bb" ref="bb"> <div class="bb" ref="bb">
<slot ref="dd"></slot> <slot ref="dd"></slot>
</div> </div>
<foo>dsdsd</foo>
</div> </div>
<div class="cc" ref="cc">${this.foo}</div> <div class="cc" ref="cc">${this.bar}</div>
` `
} }
} }

View File

@ -138,10 +138,6 @@ class Link extends Component {
) )
} }
unmounted() {
unbind(this.$refs.a, 'click', this._clickFn)
}
render() { render() {
return html` return html`
<a tabindex="0" ref="a" class="link" href=${this.to || 'javascript:;'}> <a tabindex="0" ref="a" class="link" href=${this.to || 'javascript:;'}>

View File

@ -315,7 +315,7 @@ class Scroll extends Component {
} }
// 鼠标滚动事件 // 鼠标滚动事件
this._scrollFn = bind(this.$refs.box, 'scroll', ev => { bind(this.$refs.box, 'scroll', ev => {
ev.stopPropagation() ev.stopPropagation()
// 拖拽时忽略滚动事件 // 拖拽时忽略滚动事件
if (this._active) { if (this._active) {
@ -374,7 +374,7 @@ class Scroll extends Component {
this.$emit('scroll') this.$emit('scroll')
}) })
this._yBarFn = bind(this.$refs.y, 'mousedown', ev => { bind(this.$refs.y, 'mousedown', ev => {
startY = ev.pageY startY = ev.pageY
this._active = true this._active = true
@ -383,7 +383,7 @@ class Scroll extends Component {
bind(document, 'mouseup', mouseupFn) bind(document, 'mouseup', mouseupFn)
}) })
this._xBarFn = bind(this.$refs.x, 'mousedown', ev => { bind(this.$refs.x, 'mousedown', ev => {
startX = ev.pageX startX = ev.pageX
this._active = true this._active = true
@ -396,9 +396,6 @@ class Scroll extends Component {
} }
unmounted() { unmounted() {
this.__observer.disconnect() this.__observer.disconnect()
unbind(this.$refs.box, 'scroll', this._scrollFn)
unbind(this.$refs.y, 'mousedown', this._yBarFn)
unbind(this.$refs.x, 'mousedown', this._xBarFn)
} }
render() { render() {