mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-04-30 14:39:30 +08:00
update post: code format
This commit is contained in:
parent
031317d662
commit
f69e5b86c5
1 changed files with 23 additions and 4 deletions
|
@ -243,10 +243,29 @@ function toggle(index: number) {
|
|||
|
||||
> 使用 h 渲染函数来实现一个组件。
|
||||
|
||||
```vue
|
||||
import { defineComponent, h } from 'vue'; export default defineComponent({ name: 'MyButton', props: { disabled: { type: Boolean,
|
||||
default: false, }, }, emits: ['custom-click'], setup(props, { emit, slots }) { return () => h( 'button', { disabled:
|
||||
props.disabled, onClick: () => emit('custom-click'), }, slots.default?.() ); }, });
|
||||
```js
|
||||
import { defineComponent, h } from 'vue'
|
||||
export default defineComponent({
|
||||
name: 'MyButton',
|
||||
props: {
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
emits: ['custom-click'],
|
||||
setup(props, { emit, slots }) {
|
||||
return () =>
|
||||
h(
|
||||
'button',
|
||||
{
|
||||
disabled: props.disabled,
|
||||
onClick: () => emit('custom-click')
|
||||
},
|
||||
slots.default?.()
|
||||
)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### 树组件
|
||||
|
|
Loading…
Reference in a new issue