瀏覽代碼

fix: 修复 editor 使用ref 赋值导致的 卡死

lanceJiang 8 月之前
父節點
當前提交
df5287b947
共有 1 個文件被更改,包括 3 次插入4 次删除
  1. 3 4
      src/components/MonacoEditor/index.vue

+ 3 - 4
src/components/MonacoEditor/index.vue

@@ -27,7 +27,7 @@ const props = defineProps({
 })
 const emits = defineEmits(['update:modelValue', 'change', 'editorDidMount'])
 const monacoRef = ref<HTMLElement>()
-const editor = ref()
+const editor = shallowRef()
 const _getValue = () => {
 	return editor.value?.getValue()
 }
@@ -77,9 +77,8 @@ watch(
 	}
 )
 onBeforeUnmount(() => {
-	if (editor.value) {
-		editor.value.dispose()
-	}
+	editor.value?.dispose()
+	editor.value = null
 })
 defineExpose({
 	getValue: _getValue