For AI agents: the complete documentation index is available at /vue-codemirror6/ja/llms.txt, the full documentation bundle is available at /vue-codemirror6/ja/llms-full.txt, and this page is available as Markdown at /vue-codemirror6/ja/api/events.md.
  • 日本語
  • イベント

    イベント引数発火するタイミング
    update:modelValuestring | Textテキストが変更されたとき。v-model で使われます。
    ready{ view: EditorView; state: EditorState; container: HTMLElement }エディタが生成されたとき(マウント後、クライアント側のみ)
    focusbooleanエディタがフォーカスを得た(true)または失った(false)とき
    updateViewUpdateテキスト、選択範囲、フォーカス、表示領域などビューが更新されたとき
    changeEditorStateテキストが変更されたとき。新しい状態を受け取ります。
    destroy—エディタが破棄されたとき(コンポーネントのアンマウント時)
    <script lang="ts" setup vapor>
    import type { EditorState } from '@codemirror/state';
    import type { ViewUpdate } from '@codemirror/view';
    import CodeMirror from 'vue-codemirror6';
    
    const onUpdate = (update: ViewUpdate) => {
      if (update.selectionSet) {
        console.log('selection', update.state.selection.main);
      }
    };
    
    const onChange = (state: EditorState) => {
      console.log('lines', state.doc.lines);
    };
    </script>
    
    <template>
      <code-mirror basic @update="onUpdate" @change="onChange" />
    </template>

    Web Component として使う場合、これらはネイティブの CustomEvent として発火し、引数は event.detail[0] で取得できます。モデルのイベント名は update:model-value です。