fei-editor
Version:
基于vue的代码编辑器插件
216 lines (160 loc) • 4.87 kB
Markdown
[](https://www.npmjs.com/package/fei-editor)
[](https://opensource.org/licenses/MIT)
[](https://vuejs.org/)
[](https://www.typescriptlang.org/)
基于 Vue 3 + TypeScript + Vite 的现代化代码编辑器组件,基于 Ace Editor 构建。
- 🚀 **Vue 3** - 基于 Vue 3 Composition API 构建
- 📦 **TypeScript** - 完整的 TypeScript 支持
- ⚡ **Vite** - 使用 Vite 进行快速构建
- 🎨 **Ant Design Vue** - 现代化的 UI 组件库
- 🔧 **Ace Editor** - 强大的代码编辑功能
- 📱 **响应式** - 支持移动端和桌面端
- 🎯 **轻量级** - 按需引入,体积小巧
```bash
npm install fei-editor
```
```bash
yarn add fei-editor
```
```bash
pnpm add fei-editor
```
```html
<!-- 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>
```
```javascript
import { createApp } from 'vue'
import FeiEditor from 'fei-editor'
import App from './App.vue'
const app = createApp(App)
app.use(FeiEditor)
app.mount('#app')
```
```javascript
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')
```
```vue
<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
```bash
npm install
yarn install
pnpm install
```
```bash
npm run dev
npm run build:lib
npm run build:demo
npm run lint
npm run format
npm run type-check
```
```
fei-editor/
├── src/
│ ├── components/
│ │ └── editor/
│ ├── types/
│ ├── utils/
│ └── index.ts
├── examples/
├── lib/
├── docs/
└── build/
```
[](LICENSE)
欢迎提交 Issue 和 Pull Request!
- [GitHub Issues](https://github.com/ymf-930/fei-editor/issues)
- [Gitee Issues](https://gitee.com/ymf930/fei-editor/issues)