<template>
<view>
<button @click="addText">添加文本</button>
<editor id="editor" @ready="handleEditorReady" />
</view>
</template>
<script setup>
import { getCurrentInstance } from 'vue'
const instance = getCurrentInstance()
let editorCtx
function handleEditorReady() {
console.log('1', instance)
uni
.createSelectorQuery()
.in(instance) // 不加这个获取不到context
.select('#editor')
.context((res) => {
editorCtx = res.context
console.log(editorCtx)
})
.exec()
}
function addText() {
editorCtx.insertText({
text: 'abc',
complete(err) {
console.log(err)
},
})
}
</script>
<style></style>

- 发布:2025-02-08 13:58
- 更新:2025-02-08 14:13
- 阅读:64
产品分类: uniapp/H5
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win11
HBuilderX类型: 正式
HBuilderX版本号: 4.45
浏览器平台: Edge
浏览器版本: 132.0.2957.140
项目创建方式: HBuilderX
示例代码:
操作步骤:
1、建一个普通uniapp项目,增加right-window页面并配置左右结构
2、将上述示例代码放在pages/index/index.vue中正常运行
3、将上述示例代码放在window/right-window.vue中无法正常往editor中添加文本
1、建一个普通uniapp项目,增加right-window页面并配置左右结构
2、将上述示例代码放在pages/index/index.vue中正常运行
3、将上述示例代码放在window/right-window.vue中无法正常往editor中添加文本
预期结果:
在window/right-window.vue中应可以正常往editor中添加文本
在window/right-window.vue中应可以正常往editor中添加文本
实际结果:
在window/right-window.vue中无法正常往editor中添加文本
在window/right-window.vue中无法正常往editor中添加文本
bug描述:
项目适配pc,分左右结构,左边主页面,右边增加right页面,右边需要使用editor组件,发现无法正常使用,相同代码放在左边主页面则可以正常使用
1 个回复
3***@qq.com (作者)
项目代码