Browse Source

支持切换脚本

mxd 3 years ago
parent
commit
3dd256e7e0
1 changed files with 4 additions and 1 deletions
  1. 4 1
      src/components/common/magic-monaco-editor.vue

+ 4 - 1
src/components/common/magic-monaco-editor.vue

@@ -8,7 +8,7 @@ import $i from '../../scripts/i18n.js'
 import { CommandsRegistry } from 'monaco-editor/esm/vs/platform/commands/common/commands'
 import { KeybindingsRegistry } from 'monaco-editor/esm/vs/platform/keybinding/common/keybindingsRegistry.js'
 import { ContextKeyExpr } from 'monaco-editor/esm/vs/platform/contextkey/common/contextkey.js'
-import { nextTick } from 'vue'
+import { nextTick, watch } from 'vue'
 export default {
 	props: {
 		language: { type: String, required: true },
@@ -45,6 +45,9 @@ export default {
 			value: this.value || '',
 			automaticLayout: true
 		})
+		watch(() => this.language, () => {
+			nextTick(() => this.instance.setModel(monaco.editor.createModel(this.instance.getModel().getValue(), this.language)))
+		})
 		this.instance.onDidChangeModelContent((e) => {
 			this.$emit('update:value', this.instance.getValue())
 			this.$emit('change')