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 でデータをクエリする方法
MySQL 外部キー制約 (FOREIGN KEY) はテーブルの特別なフィールドであり、主キー制約...
Canal は、Java を使用して開発された Alibaba のオープンソース プロジェクトです...
目次要約する <テンプレート> <div> 要素 <h2>{{メ...
目次1. 問題の説明2. 原因分析3. 解決策4. 処理1. 問題の説明調整センターでは、最後の 2...
HTML フォームは、さまざまな種類のユーザー入力を収集するために使用されます。 HTML フォー...
次に、ログ管理、ログのアーカイブ、ログのトラブルシューティング、イベントの転送と収集のためのコンピュ...
MySql Nullフィールド判定とIFNULL失敗処理ps: (プロセスを表示したくない場合は、S...
以前、raspbian で実行したときに opencv の一部の依存関係をパッケージ化できず、一部の...
序文今日、Xianyuを閲覧していたとき、各行の高さが同じではないことに気付きました。調べてみると、...
目次MySQL 内部結合、左結合、右結合、外部結合、複数テーブルクエリビルド環境: 1. 内なる慈恩...
目次序文シナリオ分析要約する序文数日前、友人がWeChatで私に連絡してきて、マシンがダウンタイムか...
この記事では、スライドタブを実装するためのjQueryの具体的なコードを参考までに紹介します。具体的...
会社の影響力が拡大し、製品が改良され続けるにつれて、関連するイメージデザインもそれに追いつき、徐々に...
さまざまな理由で、誰もが MySQL を再インストールする必要があると思います。 MySQL と Q...
この記事では、vueカードスタイルのクリックして切り替える画像コンポーネントを参考までに紹介します。...