瀏覽代碼

fix:Editor 开启、禁用不生效的问题

YunaiV 1 月之前
父節點
當前提交
94ae3bb48a
共有 2 個文件被更改,包括 8 次插入4 次删除
  1. 7 2
      src/components/Editor/src/Editor.vue
  2. 1 2
      src/views/mall/product/spu/form/DescriptionForm.vue

+ 7 - 2
src/components/Editor/src/Editor.vue

@@ -8,6 +8,7 @@ import { ElMessage } from 'element-plus'
 import { useLocaleStore } from '@/store/modules/locale'
 import { getRefreshToken, getTenantId } from '@/utils/auth'
 import { getUploadUrl } from '@/components/UploadFile/src/useUpload'
+import merge from 'lodash-es/merge'
 
 defineOptions({ name: 'Editor' })
 
@@ -60,7 +61,11 @@ watch(
 )
 watch(
   () => props.readonly,
-  (val) => {
+  async (val) => {
+    // 特殊:等待 editorRef 渲染完成
+    if (!editorRef.value) {
+      await nextTick()
+    }
     if (val) {
       editorRef.value?.disable()
     } else {
@@ -75,7 +80,7 @@ const handleCreated = (editor: IDomEditor) => {
 
 // 编辑器配置
 const editorConfig = computed((): IEditorConfig => {
-  return Object.assign(
+  return merge(
     {
       placeholder: '请输入内容...',
       readOnly: props.readonly,

+ 1 - 2
src/views/mall/product/spu/form/DescriptionForm.vue

@@ -3,8 +3,7 @@
   <el-form ref="formRef" :model="formData" :rules="rules" label-width="120px" :disabled="isDetail">
     <!--富文本编辑器组件-->
     <el-form-item label="商品详情" prop="description">
-      <Editor v-if="!isDetail" v-model:modelValue="formData.description" />
-      <Editor v-else :modelValue="formData.description" readonly />
+      <Editor :readonly="isDetail" v-model:modelValue="formData.description" />
     </el-form-item>
   </el-form>
 </template>