editor组件如何插入类似微信@功能,不可编辑,删除的时候整体删除
- Dominant language
- JavaScript
- Stars
- 41.6k
- Forks
- 3.7k
- Avg merge
- 7h 6m
- Merged PRs (30d)
- 6
Description
### 问题分类
HBuilderX
### 问题描述
const delta = {
"ops": [
{insert: prefixText}, // 前缀文本,使用默认样式
{
insert: `@${assistant.name_cn}`,
attributes: {
class: "assistant-tag",
contenteditable: false,
/* H5 专属 */
/* #ifdef H5 */
color: "#1976d2",
/* #endif */
/* 微信小程序专属 */
/* #ifdef MP-WEIXIN */
color: "#1976d2",
customData: "{\"type\":\"assistant\",\"editable\":false}"
/* #endif */
}
},
{
insert: " ", //
attributes: { // 关键!重置后续样式
/* #ifdef H5 */
color: "initial", // H5恢复默认
/* #endif */
/* #ifdef MP-WEIXIN */
color: "#000000", // 小程序恢复黑色
/* #endif */
}
} // 添加一个空格,使用默认样式
]
}
editorCtx.setContents({
delta: delta,
success: () => {
console.log('助手标签插入成功');
// 更新数据
this.inputMessage = prefixText + '@' + assistant.name_cn + ' ';
this.editorContent = prefixText + '@' + assistant.name_cn + ' ';
}
});
我在vue中用的是contenteditable属性,但是uniapp好像不生效
### 附加信息
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.