
基于 Vue 3 + TypeScript + Vite 的现代化代码编辑器组件,基于 Ace Editor 构建。
- 🚀 Vue 3 - 基于 Vue 3 Composition API 构建
- 📦 TypeScript - 完整的 TypeScript 支持
- ⚡ Vite - 使用 Vite 进行快速构建
- 🎨 Ant Design Vue - 现代化的 UI 组件库
- 🔧 Ace Editor - 强大的代码编辑功能
- 📱 响应式 - 支持移动端和桌面端
- 🎯 轻量级 - 按需引入,体积小巧
<!-- Vue 3 -->
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<!-- Fei Editor -->
<script src="https://unpkg.com/fei-editor@latest/lib/fei-editor.umd.js"></script>
import { createApp } from 'vue'
import FeiEditor from 'fei-editor'
import App from './App.vue'
const app = createApp(App)
app.use(FeiEditor)
app.mount('#app')
import { createApp } from 'vue'
import { Editor } from 'fei-editor'
import App from './App.vue'
const app = createApp(App)
app.component('FeiEditor', Editor)
app.mount('#app')
<template>
<div>
<FeiEditor
v-model="code"
:height="400"
:options="editorOptions"
@change="handleChange"
/>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { Editor } from 'fei-editor'
const code = ref('console.log("Hello, Fei Editor!")')
const editorOptions = {
theme: 'chrome',
mode: 'javascript',
fontSize: 14,
showGutter: true,
showPrintMargin: false,
wrap: true,
readOnly: false
}
const handleChange = (value) => {
console.log('代码变化:', value)
}
</script>
| 参数 |
说明 |
类型 |
默认值 |
| v-model |
编辑器内容 |
string |
'' |
| height |
编辑器高度 |
number | string |
300 |
| width |
编辑器宽度 |
number | string |
'100%' |
| options |
编辑器配置选项 |
object |
{} |
| readonly |
是否只读 |
boolean |
false |
| theme |
编辑器主题 |
string |
'chrome' |
| mode |
编辑器模式 |
string |
'javascript' |
| 事件名 |
说明 |
回调参数 |
| change |
内容变化时触发 |
(value: string) |
| focus |
获得焦点时触发 |
(event: Event) |
| blur |
失去焦点时触发 |
(event: Event) |
| init |
编辑器初始化完成 |
(editor: AceEditor) |
| 方法名 |
说明 |
参数 |
| getValue |
获取编辑器内容 |
- |
| setValue |
设置编辑器内容 |
(value: string) |
| setTheme |
设置主题 |
(theme: string) |
| setMode |
设置模式 |
(mode: string) |
| setReadOnly |
设置只读状态 |
(readonly: boolean) |
| resize |
调整编辑器大小 |
- |
| destroy |
销毁编辑器 |
- |
- Node.js >= 18.0.0
- npm / yarn / pnpm
# 使用 npm
npm install
# 使用 yarn
yarn install
# 使用 pnpm
pnpm install
# 启动开发服务器
npm run dev
# 构建库
npm run build:lib
# 构建演示项目
npm run build:demo
# 代码检查
npm run lint
# 代码格式化
npm run format
# TypeScript 类型检查
npm run type-check
fei-editor/
├── src/ # 源代码
│ ├── components/ # 组件
│ │ └── editor/ # 编辑器组件
│ ├── types/ # 类型定义
│ ├── utils/ # 工具函数
│ └── index.ts # 入口文件
├── examples/ # 演示项目
├── lib/ # 构建输出
├── docs/ # 文档站点
└── build/ # 构建配置
MIT
欢迎提交 Issue 和 Pull Request!