Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Vue Codemirror | 2,620 | 331 | 606 | 10 months ago | 51 | August 27, 2022 | 58 | mit | TypeScript | |
@codemirror code editor component for @vuejs | ||||||||||
Vjdesign | 407 | 1 | 9 months ago | 51 | December 05, 2022 | 14 | mit | Vue | ||
Vue 界面可视化设计器,支持任何 html 标签以及项目中引用的组件,可实现仅通过配置文件就能增加支持的组件和组件属性 | ||||||||||
Plantuml Editor | 387 | 2 years ago | 19 | mit | Vue | |||||
PlantUML online demo client | ||||||||||
Onlinejudgefe | 242 | 10 months ago | 24 | other | Vue | |||||
A multiple pages app built for OnlineJudge | ||||||||||
Vue Codemirror Lite | 215 | 49 | 180 | 6 years ago | 5 | February 17, 2018 | mit | Vue | ||
Lightweight Codemirror Component for Vue.js | ||||||||||
Ink Mde | 146 | 8 | a month ago | 49 | September 27, 2023 | 10 | mit | TypeScript | ||
A beautiful, modern, customizable Markdown editor powered by CodeMirror 6 and TypeScript | ||||||||||
Codemirror Editor Vue3 | 138 | 30 | a month ago | 95 | November 07, 2023 | 1 | mit | TypeScript | ||
CodeMirror component for Vue3 | ||||||||||
Js Encoder | 136 | a year ago | 11 | mit | JavaScript | |||||
JS-Encoder is an online front-end code editor(前端在线代码编辑器)built with vue and codemirror. If you want to support JS-Encoder, click star 💗 to support it! | ||||||||||
V Markdown Editor | 99 | 8 | 3 | 2 years ago | 26 | July 11, 2020 | 21 | mit | Vue | |
Vue.js Markdown Editor component | ||||||||||
Vue Cm | 45 | 3 | 1 | 6 years ago | 3 | August 03, 2017 | 1 | mit | JavaScript | |
CodeMirror component for Vue.js |
CodeMirror(6) component for Vue(3).
vue-codemirror
v5/v6 has been released. This is a new version based on CodeMirror@6 and is available to Vue3 only. Since CodeMirror@6 is developed with native ES Modules, the new version will no longer support direct browser references to UMD modules. In short, the new version is completely NOT compatible with previous versions. If you wish to continue using Vue2 or a lower version of CodeMirror, please refer to the legacy versions below.
This example site contains most of what you want.
yarn add codemirror vue-codemirror
npm install codemirror vue-codemirror --save
# CodeMirror languages...
yarn add @codemirror/lang-html
yarn add @codemirror/lang-json
yarn add @codemirror/lang-javascript
# CodeMirror themes...
yarn add @codemirror/theme-one-dark
# more CodeMirror packages...
package.json
e.g.
"dependencies": {
"@codemirror/state": "6.x"
}
import { EditorState } from '@codemirror/state'
<template>
<codemirror
v-model="code"
placeholder="Code goes here..."
:style="{ height: '400px' }"
:autofocus="true"
:indent-with-tab="true"
:tab-size="2"
:extensions="extensions"
@ready="handleReady"
@change="log('change', $event)"
@focus="log('focus', $event)"
@blur="log('blur', $event)"
/>
</template>
<script>
import { defineComponent, ref, shallowRef } from 'vue'
import { Codemirror } from 'vue-codemirror'
import { javascript } from '@codemirror/lang-javascript'
import { oneDark } from '@codemirror/theme-one-dark'
export default defineComponent({
components: {
Codemirror
},
setup() {
const code = ref(`console.log('Hello, world!')`)
const extensions = [javascript(), oneDark]
// Codemirror EditorView instance ref
const view = shallowRef()
const handleReady = (payload) => {
view.value = payload.view
}
// Status is available at all times via Codemirror EditorView
const getCodemirrorStates = () => {
const state = view.value.state
const ranges = state.selection.ranges
const selected = ranges.reduce((r, range) => r + range.to - range.from, 0)
const cursor = ranges[0].anchor
const length = state.doc.length
const lines = state.doc.lines
// more state info ...
// return ...
}
return {
code,
extensions,
handleReady,
log: console.log
}
}
})
</script>
import { createApp } from 'vue'
import { basicSetup } from 'codemirror'
import VueCodemirror from 'vue-codemirror'
const app = createApp()
app.use(VueCodemirror, {
// optional default global options
autofocus: true,
disabled: false,
indentWithTab: true,
tabSize: 2,
placeholder: 'Code goes here...',
extensions: [basicSetup]
// ...
})
prop | description | type | default |
---|---|---|---|
modelValue | The input values accepted by the component also support two-way binding. | String |
'' |
autofocus | Focus editor immediately after mounted. | Boolean |
false |
disabled | Disable input behavior and disable change state. | Boolean |
false |
indentWithTab | Bind keyboard Tab key event. | Boolean |
true |
tabSize | Specify the indent when the Tab key is pressed. | Number |
2 |
placeholder | Display when empty. | String |
'' |
style | The CSS style object that acts on the CodeMirror itself. | Object |
{} |
phrases | Codemirror internationalization phrases. | Object |
{} |
autoDestroy | Auto destroy the CodeMirror instance before the component unmount. | Boolean |
true |
extensions | Passed to CodeMirror EditorState.create({ extensions })
|
Extension |
[] |
selection | Passed to CodeMirror EditorState.create({ selection })
|
EditorSelection |
- |
root | Passed to CodeMirror new EditorView({ root })
|
ShadowRoot | Document |
- |
event | description | params |
---|---|---|
update:modelValue |
Only when the CodeMirror content (doc) has changed. | (value: string, viewUpdate: ViewUpdate) |
change | ditto | ditto |
update | When any state of CodeMirror changes. | (viewUpdate: ViewUpdate) |
focus | When CodeMirror focused. | (viewUpdate: ViewUpdate) |
blur | When CodeMirror blurred. | (viewUpdate: ViewUpdate) |
ready | When editor component mounted. | (payload: { view: EditorView; state: EditorState; container: HTMLDivElement }) |
The basic-setup extension is integrated by default in the vue-codemirror configuration and is intended as a handy helper to quickly set up CodeMirror without having to install and import a lot of standalone packages. If you want to override the default behavior of the config, just pass the empty array when installing the component globally.
app.use(VueCodemirror, {
// keep the global default extensions empty
extensions: []
})
Detailed changes for each release are documented in the release notes.
Licensed under the MIT License.