收藏
回答

[组件bug]editor组件的bindblur事件获取不到输入的内容

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug editor 工具 stable 1.06.2407120 3.8.8

代码片段就一个editor组件,绑定bindblur事件,输入内容后失去焦点,打印出来的text,html都只有换行符,获取不到输入的内容

回答关注问题邀请回答
收藏

1 个回答

  • xplee
    xplee
    06-17

    不是这么用的,下面是正确获取editor内容的写法

    <view>
      <editor id="editor" class="editor" placeholder="在此输入" bindblur="bindblur" bindready="onEditorReady"/>
    </view>
    


    onEditorReady() {
      let that = this
      wx.createSelectorQuery()
        .select('#editor')
        .context()
        .exec( res => {
          if(res) {
            const editorContext = res[0].context
            that.editorCtx = editorContext
          }
        })
    },
    
    bindblur(e) {
      // console.log('blur:', this.editorCtx)
      this.editorCtx.getContents({
        success: function(res) {
          console.log(res)
        },
        fail: function(error) {
          console.log(error)
        }
      })
    }
    
    06-17
    有用
    回复
登录 后发表内容