1***@qq.com
1***@qq.com
  • 发布:2025-06-05 16:52
  • 更新:2025-06-05 17:44
  • 阅读:64

h5端 editor组件 使用ctrl v 粘贴会自动触发失焦

分类:uni-app
2025-06-05 16:52 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com (作者)

有大佬知道怎么解决吗

DCloud_UNI_yuhe

DCloud_UNI_yuhe

我测试了一下,没有发现这个失焦的问题

  • 1***@qq.com (作者)

    第一次点击输入框的获取焦点的时候我会插入一个图片 // 图片HTML

    const assistantImgTag = <img src="${imgResult.src}" class ="ai-assistant-tag" data-custom="id=${lastAssistant.id};name=${lastAssistant.name_cn}">;

    this.editorCtx.setContents({

    html: assistantImgTag,

    success: () => {

    this.editorContent = assistantImgTag ? "@" + lastAssistant.name_cn+ " " : "";

    this.inputMessage = assistantImgTag ? "@" + lastAssistant.name_cn + " " : "";

    // 检查focus方法是否存在再调用

    if (this.editorCtx && typeof this.editorCtx.focus === 'function') {

    this.editorCtx.focus();

    } else {

    // console.log('编辑器不支持focus方法');

    }

    }

    });

    });

    2025-06-05 17:45

  • 1***@qq.com (作者)

    然后ctrl v 粘贴 就会触发失去焦点

    2025-06-05 17:45

  • DCloud_UNI_yuhe

    回复 1***@qq.com: 请提供一下完整的测试实例

    2025-06-05 17:49

1***@qq.com

1***@qq.com (作者)

结构是这样的<view class="input-wrapper"> <view class="editor-container"> <editor id="editor" class="rich-editor" placeholder="'发送消息...'" read-only="isLoading" img-del="false" show-img-size
show-img-toolbar
show-img-resize
contenteditable="true"
@ready="onEditorReady"
@input="onEditorInput"
@blur="onEditorBlur"
@focus="onEditorFocus"
></editor>

要回复问题请先登录注册