From f69e5b86c53021085476ed79fcf1d3ad2478a933 Mon Sep 17 00:00:00 2001 From: Sevichecc <91365763+Sevichecc@users.noreply.github.com> Date: Mon, 22 Aug 2022 22:54:51 +0800 Subject: [PATCH] update post: code format --- urara/2022-08-12-vue-challenges.md | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/urara/2022-08-12-vue-challenges.md b/urara/2022-08-12-vue-challenges.md index 0c05db8e..4c5efeb2 100644 --- a/urara/2022-08-12-vue-challenges.md +++ b/urara/2022-08-12-vue-challenges.md @@ -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?.() + ) + } +}) ``` ### 树组件