一键导入
n-code
Code component for displaying syntax-highlighted code. Invoke when user needs to display code snippets with syntax highlighting in Naive UI.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Code component for displaying syntax-highlighted code. Invoke when user needs to display code snippets with syntax highlighting in Naive UI.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
FormCreate(运行态渲染器)使用与扩展助手:围绕 rule/option/api 的编写、调试与迁移,覆盖 v-model:api / create 获取实例、字段联动(control/computed)、校验(validate)、远程 fetch、事件注入(inject/formCreateInject)、序列化保存回显(parseJson/toJson)以及多 UI 栈(Antd/Naive/Vant/Arco/TDesign/Element)props/on 差异。权威口径以 `AGENTS.md` 与 `references/types.md` 为准;涉及设计器 ref/config 请用 **FcDesigner使用助手**,涉及安装与包名请选择 **FormCreate安装助手**。
Naive UI Skills Library - A comprehensive skill library for AI agents to understand and utilize Naive UI components. Invoke when user needs to work with Naive UI components, theming, i18n, dark mode, or design specifications.
Work on the Vane server app in apps/server. Use when adding, modifying, reviewing, or debugging server routes, serve-layer data access, middlewares, auth, logging, uploads, database-backed features, or Express response behavior in this repository.
Affix component that makes content stick to fixed places when scrolling. Invoke when user needs to implement sticky positioning or fixed elements in Naive UI.
Alert component for displaying important messages and notifications. Invoke when user needs to show contextual feedback messages with different types and styles in Naive UI.
Anchor component for navigation and table of contents. Invoke when user needs to implement anchor navigation, table of contents, or scroll-based navigation highlighting in Naive UI.
| name | n-code |
| description | Code component for displaying syntax-highlighted code. Invoke when user needs to display code snippets with syntax highlighting in Naive UI. |
| metadata | {"author":"jiaiyan","version":"1.0.0"} |
Code component for displaying syntax-highlighted code blocks with support for multiple languages.
Use this component when:
Invoke this skill when:
Important: Naive UI does not include highlight.js by default. You must configure it before using the Code component.
<template>
<n-config-provider :hljs="hljs">
<my-app />
</n-config-provider>
</template>
<script setup>
import hljs from 'highlight.js/lib/core';
import javascript from 'highlight.js/lib/languages/javascript';
import python from 'highlight.js/lib/languages/python';
hljs.registerLanguage('javascript', javascript);
hljs.registerLanguage('python', python);
// Register only the languages you need to reduce bundle size
</script>
| Name | Type | Default | Description |
|---|---|---|---|
| code | string | '' | Incoming code string. |
| hljs | Object | undefined | If you want to set hljs locally, pass it using this prop. |
| inline | boolean | false | Whether the code is displayed as inline. |
| language | string | undefined | Code language in highlightjs. |
| show-line-numbers | boolean | false | Whether to show line numbers. Won't work if inline or word-wrap is true. |
| trim | boolean | true | Whether to display trimmed code. |
| word-wrap | boolean | false | Whether to display word-wrapped code. |
<template>
<div style="overflow: auto">
<n-space vertical :size="16">
<n-code
code="
function sleep (ms = 1000) {
return new Promise(resolve => setTimeout(resolve, ms))
}
"
language="javascript"
/>
<n-code
code="
def say_hello():
print('Hello Naive UI')
"
language="python"
/>
</n-space>
</div>
</template>
<template>
<div>
JavaScript
<n-code :code="code" language="javascript" inline />
is awesome!
</div>
</template>
<script setup>
const code = 'const x = 1';
</script>
<template>
<n-code :code="longCode" language="js" word-wrap />
</template>
<script setup>
const longCode = `const veryLongVariableName = 'This is a very long string that would normally overflow the container'`;
</script>
<template>
<div style="overflow: auto">
<n-code :code="code" language="cpp" show-line-numbers />
</div>
</template>
<script setup>
const code = `#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}`;
</script>
<template>
<div class="code-container">
<n-button size="tiny" class="copy-btn" @click="handleCopy">
{{ copied ? 'Copied!' : 'Copy' }}
</n-button>
<n-code :code="code" language="javascript" />
</div>
</template>
<script setup>
import { ref } from 'vue';
const code = `function hello() {
console.log('Hello, World!')
}`;
const copied = ref(false);
const handleCopy = async () => {
await navigator.clipboard.writeText(code);
copied.value = true;
setTimeout(() => {
copied.value = false;
}, 2000);
};
</script>
<style scoped>
.code-container {
position: relative;
}
.copy-btn {
position: absolute;
top: 8px;
right: 8px;
}
</style>
<template>
<div>
<n-tabs v-model:value="activeTab">
<n-tab-pane name="js" tab="JavaScript">
<n-code :code="jsCode" language="javascript" />
</n-tab-pane>
<n-tab-pane name="ts" tab="TypeScript">
<n-code :code="tsCode" language="typescript" />
</n-tab-pane>
</n-tabs>
</div>
</template>
<script setup>
import { ref } from 'vue';
const activeTab = ref('js');
const jsCode = `function greet(name) {
return \`Hello, \${name}!\`
}`;
const tsCode = `function greet(name: string): string {
return \`Hello, \${name}!\`
}`;
</script>
<template>
<n-code :hljs="hljs" :code="code" language="rust" />
</template>
<script setup>
import hljs from 'highlight.js/lib/core';
import rust from 'highlight.js/lib/languages/rust';
hljs.registerLanguage('rust', rust);
const code = `fn main() {
println!("Hello, World!");
}`;
</script>
<template>
<n-card title="Example Code">
<n-code :code="code" language="javascript" show-line-numbers />
</n-card>
</template>
<script setup>
const code = `// Example function
function example() {
return true
}`;
</script>
Register languages on demand: Only import the languages you need to reduce bundle size
import hljs from 'highlight.js/lib/core';
import javascript from 'highlight.js/lib/languages/javascript';
hljs.registerLanguage('javascript', javascript);
Use overflow container: Wrap code blocks in overflow containers for horizontal scrolling
<div style="overflow: auto">
<n-code :code="code" language="javascript" />
</div>
Use word-wrap for long lines: Enable word-wrap when horizontal scrolling is not desired
<n-code :code="code" language="javascript" word-wrap />
Configure hljs globally: Use n-config-provider to set hljs once for all Code components
<n-config-provider :hljs="hljs">
<app />
</n-config-provider>
Use inline mode sparingly: Inline code is best for short snippets within text
Use
<n-code code="const x = 1" language="javascript" inline />
for inline code.
Line numbers with block code: Use show-line-numbers for longer code blocks
<n-code :code="code" language="python" show-line-numbers />