For AI agents: the complete documentation index is available at /vue-codemirror6/zh/llms.txt, the full documentation bundle is available at /vue-codemirror6/zh/llms-full.txt, and this page is available as Markdown at /vue-codemirror6/zh/api/index.md.
  • 简体中文
  • API 概览

    CodeMirror 组件提供三类 API:

    页面内容
    Props配置编辑器的选项。修改后无需重新创建编辑器即可生效。
    事件加载完成、焦点变化、文本变更和销毁的通知。
    实例 API通过模板 ref 可以使用的属性和方法。
    <script lang="ts" setup vapor>
    import { javascript } from '@codemirror/lang-javascript';
    import { ref } from 'vue';
    import CodeMirror, { type CodeMirrorExposed } from 'vue-codemirror6';
    
    const value = ref('');
    const cm = ref<CodeMirrorExposed>();
    </script>
    
    <template>
      <code-mirror
        ref="cm"
        v-model="value"
        basic
        :lang="javascript()"
        @ready="() => cm?.view?.focus()"
      />
    </template>