From 3ed3f41e2d0f887ada299ebbc9ad76cf0af78387 Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 17 Mar 2023 18:29:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96button,=20link,=20passwd?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/form/button.js | 11 +++++------ src/form/link.js | 13 ++++++------- src/form/passwd.js | 37 ++++++++++++++++++++++--------------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/form/button.js b/src/form/button.js index a974b2d..c287dfe 100644 --- a/src/form/button.js +++ b/src/form/button.js @@ -4,7 +4,7 @@ * @date 2023/03/06 15:17:25 */ -import { css, html, Component, $, nextTick } from '@bd/core' +import { css, html, Component, nextTick } from '@bd/core' import '../icon/index.js' class Button extends Component { @@ -244,10 +244,9 @@ class Button extends Component { mounted() { if (this.autofocus) { - let $btn = $('button', this.root) - $btn.setAttribute('autofocus', '') + this.$refs.btn.setAttribute('autofocus', '') // 需要focus()才能聚焦成功 - nextTick(_ => $btn.focus()) + nextTick(_ => this.$refs.btn.focus()) } } @@ -257,9 +256,9 @@ class Button extends Component { render() { return html` - ` } diff --git a/src/form/link.js b/src/form/link.js index 3e25971..cf676a8 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 '@bd/core' +import { css, html, Component, bind, unbind, nextTick } from '@bd/core' class Link extends Component { static props = { type: 'primary', @@ -106,17 +106,16 @@ class Link extends Component { ] mounted() { - let $a = $('.link', this.root) this.stamp = 0 if (this.autofocus) { - $a.setAttribute('autofocus', '') + this.$refs.a.setAttribute('autofocus', '') // 需要focus()才能聚焦成功 - nextTick(_ => $a.focus()) + nextTick(_ => this.$refs.a.focus()) } this._clickFn = bind( - $a, + this.$refs.a, 'click', ev => { let { disabled, lazy } = this @@ -141,12 +140,12 @@ class Link extends Component { } unmounted() { - unbind($('.link', this.root), 'click', this._clickFn) + unbind(this.$refs.a, 'click', this._clickFn) } render() { return html` - + ` diff --git a/src/form/passwd.js b/src/form/passwd.js index 7d95aad..b396a37 100644 --- a/src/form/passwd.js +++ b/src/form/passwd.js @@ -3,7 +3,7 @@ * @author yutent * @date 2023/03/16 18:05:43 */ -import { css, html, Component, $, bind, unbind, nextTick } from '@bd/core' +import { css, html, Component, bind, unbind, nextTick } from '@bd/core' import '../icon/index.js' class Passwd extends Component { @@ -223,33 +223,40 @@ class Passwd extends Component { ] mounted() { - let $input = $('input', this.root) - let $icon = $('.icon', this.root) - if (this.autofocus) { - $input.setAttribute('autofocus', '') + this.$refs.input.setAttribute('autofocus', '') // 需要focus()才能聚焦成功 - nextTick(_ => $input.focus()) + nextTick(_ => this.$refs.input.focus()) } + } - bind($icon, 'click', ev => { - this._type = this._type === 'password' ? '' : 'password' - }) + iconClick(ev) { + if (this.readonly || this.disabled) { + return + } + this._type = this._type === 'password' ? '' : 'password' + } - bind($input, 'input', ev => { - ev.stopPropagation() - this.value = ev.target.value - this.$emit('input', { data: this.value }) - }) + handleInput(ev) { + this.value = ev.target.value } render() { return html`
- +