完成按钮组件
parent
8ea85ba562
commit
459c6a81f7
|
@ -18,7 +18,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
|
||||||
<link rel="stylesheet" href="/dist/css/reset-basic.css">
|
<link rel="stylesheet" href="/dist/css/reset-basic.css">
|
||||||
<script async src="//jscdn.ink/es-module-shims/1.6.3/es-module-shims.wasm.js"></script>
|
<script async src="//jscdn.ink/es-module-shims/1.6.3/es-module-shims.wasm.js"></script>
|
||||||
<script type="importmap">{"imports":{"es.shim":"//jscdn.ink/es.shim/2.1.1/index.js","vue":"//jscdn.ink/vue/3.2.47/vue.runtime.esm-browser.prod.js","vue-router":"//jscdn.ink/@bytedo/vue-router/4.1.6/vue-router.js","fetch":"//jscdn.ink/@bytedo/fetch/2.1.5/next.js","@bd/core":"//jscdn.ink/@bd/core/1.4.0/index.js"}}</script>
|
<script type="importmap">{"imports":{"es.shim":"//jscdn.ink/es.shim/2.1.1/index.js","vue":"//jscdn.ink/vue/3.2.47/vue.runtime.esm-browser.prod.js","vue-router":"//jscdn.ink/@bytedo/vue-router/4.1.6/vue-router.js","fetch":"//jscdn.ink/@bytedo/fetch/2.1.5/next.js","@bd/core":"//jscdn.ink/@bd/core/1.4.1/index.js"}}</script>
|
||||||
<style></style>
|
<style></style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* @date 2023/03/06 15:17:25
|
* @date 2023/03/06 15:17:25
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { css, html, Component } from '@bd/core'
|
import { css, html, Component, $, nextTick } from '@bd/core'
|
||||||
import '../icon/index.js'
|
import '../icon/index.js'
|
||||||
|
|
||||||
class Button extends Component {
|
class Button extends Component {
|
||||||
|
@ -13,7 +13,19 @@ class Button extends Component {
|
||||||
icon: '',
|
icon: '',
|
||||||
size: 'l',
|
size: 'l',
|
||||||
autofocus: false,
|
autofocus: false,
|
||||||
loading: false,
|
loading: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
observer(val) {
|
||||||
|
if (val) {
|
||||||
|
this.cacheIcon = this.icon
|
||||||
|
this.icon = 'loading'
|
||||||
|
} else {
|
||||||
|
this.icon = this.cacheIcon || ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
list: Array,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
lazy: 0 // 并发拦截时间, 单位毫秒
|
lazy: 0 // 并发拦截时间, 单位毫秒
|
||||||
}
|
}
|
||||||
|
@ -234,11 +246,21 @@ class Button extends Component {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
if (this.autofocus) {
|
||||||
|
let $btn = $('button', this.root)
|
||||||
|
$btn.setAttribute('autofocus', '')
|
||||||
|
// 需要focus()才能聚焦成功
|
||||||
|
nextTick(_ => $btn.focus())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return html`
|
return html`
|
||||||
<button disabled=${this.disabled}>
|
<button disabled=${this.disabled}>
|
||||||
<wc-icon class="icon" is="${this.icon}"></wc-icon>
|
<wc-icon class="icon" is=${this.icon}></wc-icon>
|
||||||
<slot />
|
<slot />
|
||||||
|
<p>${this.list.map(it => it)}</p>
|
||||||
</button>
|
</button>
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue