feat(demos): 添加函数式组件(TSX)示例并引入 highlight.js

This commit is contained in:
严浩
2025-10-25 00:18:26 +08:00
parent 83c5e14789
commit 33ee02bce6
5 changed files with 42 additions and 8 deletions

View File

@@ -1,8 +1,37 @@
<script setup lang="ts">
<script setup lang="tsx">
import type { FunctionalComponent } from 'vue';
import hljs from 'highlight.js/lib/core';
import json from 'highlight.js/lib/languages/json';
hljs.registerLanguage('json', json);
definePage({
meta: {
link: !false,
link: true,
title: 'Functional Component Demo',
},
});
const FComponent: FunctionalComponent<{ prop: string }> = (props /* context */) => (
<>
<NBlockquote>
函数式组件文档:
<a
class="text-blue-500 hover:text-blue-600 transition-colors"
href="https://cn.vuejs.org/guide/extras/render-function#typing-functional-components"
rel="noopener noreferrer"
target="_blank"
>
Render Function & JSX
</a>
</NBlockquote>
<p class="my-4">这是一个函数式组件它接收到的 prop 值为</p>
<NCode code={JSON.stringify(props, null, 2)} language="json" hljs={hljs} />
</>
);
</script>
<template><div>Demos</div></template>
<template>
<NCard title="函数式组件TSX示例">
<FComponent prop="some-prop-value" />
</NCard>
</template>