monaco-editor-vueの公式ソースコードは次のとおりです。 インデックス 'monaco-editor/esm/vs/editor/editor.api' から * を monaco としてインポートします。 関数noop() { } エクスポート { モナコ }; エクスポートデフォルト{ 名前: 'MonacoEditor'、 小道具: { diffEditor: { type: Boolean, default: false }, // diff モードを使用するかどうか width: { type: [String, Number], default: '100%' }, 高さ: {タイプ: [文字列、数値]、デフォルト: '100%'}, オリジナル: 文字列, // 差分モードでのみ有効 値: 文字列, 言語: {タイプ: 文字列、デフォルト: 'javascript'}, テーマ: {タイプ: 文字列、デフォルト: 'vs'}, オプション: {type: Object, default() {return {};}}, editorMounted: {タイプ: Function、デフォルト: noop}, editorBeforeMount: {タイプ: 関数、デフォルト: noop} }, 時計: オプション: 深い:本当、 ハンドラ(オプション) { this.editor && this.editor.updateOptions(オプション); } }, 価値() { this.editor && this.value !== this._getValue() && this._setValue(this.value); }, 言語() { if(!this.editor) 戻り値: if(this.diffEditor){ // diffモードで言語を更新 const { オリジナル、変更済み } = this.editor.getModel(); monaco.editor.setModelLanguage(オリジナル、this.language); monaco.editor.setModelLanguage(変更済み、this.language); }それ以外 モデル言語を設定します。 }, テーマ() { this.editor && monaco.editor.setTheme(this.theme); }, スタイル() { this.editor && this.$nextTick(() => { エディタのレイアウトをカスタマイズします。 }); } }, 計算: { スタイル() { 戻る { 幅: !/^\d+$/.test(this.width) ? this.width: `${this.width}px`, 高さ: !/^\d+$/.test(this.height) ? this.height: `${this.height}px` } } }, マウントされた(){ これは、Monaco を初期化します。 }, 破棄する前に() { this.editor と this.editor.dispose(); }, レンダリング (h) { 戻る ( <div class="monaco_editor_container" style={this.style}></div> ); }, メソッド: { initMonaco() { const { 値、言語、テーマ、オプション } = this; Object.assign(options, this._editorBeforeMount()); //エディターの初期化前 this.editor = monaco.editor[this.diffEditor ? 'createDiffEditor' : 'create'](this.$el, { 値: 値、 言語: 言語、 テーマ: テーマ、 ...オプション }); this.diffEditor && this._setModel(this.value, this.original); this._editorMounted(this.editor); //エディターが初期化された後}, _getEditor() { if(!this.editor) は null を返します。 this.diffEditor を返します。this.editor.modifiedEditor : this.editor; }, _setModel(value, original) { //diffモードでモデルを設定する const { 言語 } = this; 元のモデルを monaco.editor.createModel(元のモデル、言語); 定数 modifiedModel = monaco.editor.createModel(値、言語); this.editor.setModel({ オリジナル: オリジナルモデル、 変更: modifiedModel }); }, _setValue(値) { エディターを this._getEditor() にします。 if(editor) は editor.setValue(value) を返します。 }, _getValue() { エディターを this._getEditor() にします。 if(!editor) '' を返します。 editor.getValue() を返します。 }, _editorBeforeMount() { const オプション = this.editorBeforeMount(monaco); オプションを返します || {}; }, _editorMounted(エディター) { this.editorMounted(エディター、モナコ); if(this.diffEditor){ editor.onDidUpdateDiff((イベント) => { 定数値 = this._getValue(); this._emitChange(値、イベント); }); }それ以外{ editor.onDidChangeModelContent(イベント => { 定数値 = this._getValue(); this._emitChange(値、イベント); }); } }, _emitChange(値、イベント) { this.$emit('change', 値, イベント); this.$emit('入力', 値); } } } Vue を使用する場合、上記ライブラリの ref = "" を定義し、 次のコードを参照してください テスト <テンプレート> <div> <MonacoEditor ref="exampleEditor" width="100%" height="300" theme="vs-dark" language="javascript" :options="options" @change="codeInput" /> </div> </テンプレート> <スクリプト> 'monaco-editor-vue' から MonacoEditor をインポートします。 エクスポートデフォルト{ コンポーネント: モナコ編集者 }, データ() { 戻る { } }, 作成前() { }, マウント() { }, メソッド: { this.$refs.exampleEditor._setValue('') } } これで、ソースコード付きのリファレンスライブラリのメソッドを使用した vue に関するこの記事は終了です。リファレンスライブラリを使用した vue の関連コンテンツについては、123WORDPRESS.COM の以前の記事を検索するか、次の関連記事を引き続き参照してください。今後とも 123WORDPRESS.COM を応援していただければ幸いです。 以下もご興味があるかもしれません:
|
>>: DQL コマンドを使用して MySQL でデータをクエリする方法
必要な方はどなたでも参考にしてください。試してみて問題が見つかった場合は、メッセージを残してお知らせ...
問題: mybatis によって返される null 型のデータが消え、フロントエンドの表示にエラーが...
目次1: カプセル化の考え方2. 包装工程3: ドットインジケーター4: 左と右のインジケーター5:...
Linux では、すべてがファイルであり (ディレクトリもファイルです)、各ファイルにはユーザーに対...
1. 基本的な文法コードをコピーコードは次のとおりです。埋め込み src=url注: 埋め込みはさま...
目次単一コンテンツ投影マルチコンテンツ投影単一条件のコンテンツ投影アプリ-人物-htmlアプリ担当者...
一般的な CSS コードでは、UI レイアウトや互換性に関して軽微な問題が発生するだけです。しかし、...
目次序文1. 取引の基本原則の簡単な分析原子性:持続性分離:一貫性: 2. 分離レベルの基本原理の分...
この記事では、例を使用して MySQL カーソルの原理と使用方法を説明します。ご参考までに、詳細は以...
目次1.配列を初期化する2. 配列の合計、最大値、最小値3. エラー値をフィルタリングする4. 論理...
この記事では主に、MySQL の Aborted アラームに関する関連コンテンツを紹介し、参考と学習...
Linux CD とはどういう意味ですか? Linux では、cd はディレクトリの変更を意味します...
この記事は、100 回書かれ、質問された CSS の質問を記念するためのものです。聞く: CSS セ...
具体的なコードは次のとおりです。 <div id="ボックス"> &...
1. Vueルーティングの権限制御には一般的に2つの方法がありますa. ルーティングメタ情報(メタ)...