Monokeros
Monokeros
  • 发布:2024-09-18 20:20
  • 更新:2024-09-19 15:33
  • 阅读:48

【报Bug】editor的context没有setContents函数

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: Win11

HBuilderX类型: 正式

HBuilderX版本号: 4.24

第三方开发者工具版本号: Stable 1.06.2405020

基础库版本号: 3.5.2

项目创建方式: HBuilderX

示例代码:
<template>  
    <view>  
        <view style="margin-top:88px;">  
            <view>Test article</view>  
            <view><editor id="test" @ready="editorReady"></editor></view>  
        </view>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  

            }  
        },  
        methods:   
        {  
            editorReady()  
            {  
                uni.createSelectorQuery().select('#test').context((nodeContext) =>  
                {  
                    console.log('>>>>>', nodeContext)  
                    nodeContext.setContents({  
                        html: '<p>abcdefg</p>'  
                    })  
                }).exec()  
            }  
        }  
    }  
</script>  

<style>  

</style>

操作步骤:

以上page直接打开

预期结果:

editor容器显示abcdefg

实际结果:

小程序模拟器中:

[system] WeChatLib: 3.5.2 (2024.7.31 22:00:40)  
[system] Subpackages: N/A  
[system] LazyCodeLoading: false  
App.vue:56 [App.vue] Launch, os = ios, deviceId = 17259582958709331537  
ob.user.js:17 [UserOB] Initialized  
App.vue:69 [App.vue] App Show  
[基础库] 正在使用灰度中的基础库 3.5.2 进行调试。如有问题,请前往工具栏-详情-本地设置更改基础库版本。  
[system] Launch Time: 706 ms  
articleview.vue:23 >>>>> {context: hae}  
TypeError: nodeContext.setContents is not a function  
    at Object.<anonymous> (articleview.vue:24)  
    at Function.<anonymous> (WAServiceMainContext.js?t=wechat&s=1726539162520&v=3.5.2:1)  
    at :34961/appservice/<SelectorQuery callback function>  
    at WAServiceMainContext.js?t=wechat&s=1726539162520&v=3.5.2:1  
    at WAServiceMainContext.js?t=wechat&s=1726539162520&v=3.5.2:1  
    at Array.forEach (<anonymous>)  
    at WAServiceMainContext.js?t=wechat&s=1726539162520&v=3.5.2:1  
    at WAServiceMainContext.js?t=wechat&s=1726539162520&v=3.5.2:1  
    at WASubContext.js?t=wechat&s=1726539162520&v=3.5.2:1  
    at ge (WASubContext.js?t=wechat&s=1726539162520&v=3.5.2:1)(env: Windows,mp,1.06.2405020; lib: 3.5.2)

bug描述:

<editor>获取了context后setContents提示is not a function

2024-09-18 20:20 负责人:无 分享
已邀请:
Monokeros

Monokeros (作者)

补充一下,这个问题只出现在微信小程序中(真机和模拟器都有),但H5(无论公众号还是网页)都没问题。

DCloud_UNI_yuhe

DCloud_UNI_yuhe

你好,你是vue2出现的这个问题,还是vue3出现的问题?

DCloud_UNI_yuhe

DCloud_UNI_yuhe

你这是少了一个context,需要这样来调用:`nodeContext.context

<script>  
    export default {  
        data() {  
            return {  

            }  
        },  
        methods: {  
            editorReady() {  
                uni.createSelectorQuery().select('#test').context((nodeContext) => {  
                    console.log('>>>>>', nodeContext)  
                    nodeContext.context.setContents({  
                        html: '<p>abcdefg</p>'  
                    })  
                }).exec()  
            }  
        }  
    }  
</script>
  • Monokeros (作者)

    感谢,这个方式确实解决了page的问题,但当这个editor在component里时还是不行。虽然不报错了,但没任何反应……我还特意加了个timeout怕是DOM渲染问题。


            methods:   
    {
    onEditorReady()
    {
    console.log('[cj-richtext-editor] Editor ready')
    setTimeout(()=>{
    uni.createSelectorQuery().in(this).select('#'+this.id).context((nodeContext) =>
    {
    console.log('>>>>> ', nodeContext.context)
    this.editorCtx = nodeContext.context

    if ( this.content )
    {
    if ( typeof(this.content) == 'object' )
    this.editorCtx.setContents({
    delta: this.content
    })
    else
    this.editorCtx.setContents({
    html: this.content
    })
    }
    this.$emit('ready', this.editorCtx)
    console.log('>>>>> 2')
    }).exec()
    }, 1000)
    }
    }

    log输出


    [cj-richtext-editor] Editor ready  
    [pages/home/articleview] [Deprecation] 'selectable' attribute of '<text>' is deprecated. Please use 'user-select' instead.
    cj-richtext-editor.vue:144 >>>>> hae {editorId: 0, webviewId: 806}
    cj-richtext-editor.vue:159 >>>>> 2

    2024-09-19 15:22

  • Monokeros (作者)

    UI层也确实一直显示placeholder的内容,所以我确定是没完成渲染,不是ui排布的问题…… =___=||

    2024-09-19 15:23

  • DCloud_UNI_yuhe

    回复 Monokeros: 好的,我看一下

    2024-09-19 15:29

DCloud_UNI_yuhe

DCloud_UNI_yuhe

似乎与放到组件里面,也没有关系,我这里测试放到组件里面也是正常的

  • Monokeros (作者)

    @@" 这就很奇怪了,而且这个bug我是刚发现的,同样的代码从公众号H5一直过来的component,在H5那边完全没问题……我再试试,谢谢!

    2024-09-19 15:46

要回复问题请先登录注册