V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
sunmoon1983
V2EX  ›  前端开发

各位大佬们, uni-app 中可以监听 uni-esayinput 的光标移动事件吗?

  •  
  •   sunmoon1983 · 7 天前 · 194 次点击

    就像 QQ 的聊天输入框一样,我先输入十个字,然后把光标移动到第三个字后面,这时候我想记录一下光标的位置,然后在当前位置插入一个 emoji 表情, 请问有这种事件吗? 今天我尝试了 focue 和 input 事件,貌似都不太行! 主要的代码:

          <uni-easyinput
            v-if="sendMsgWay === 0"
            class="builder-main__content"
            confirmType="send"
            ref="easyInput"
            :placeholder="placeholder"
            :clearable="false"
            v-model="message"
            @input="onInput"
            @focus="onInputFocus"
            @blur="onInputBlur"
            @confirm="onSendMessage"
          />
    
    const cursorPosition = ref({})
    //记录光标位置
    const updateCursorPosition = ()=>{
      uni.getSelectedTextRange({
        success: res => {
          cursorPosition.value = {...res}
        }
      })
    }
    function onInputFocus(e) {
      updateCursorPosition();
    }
    function onInputBlur(){
      updateCursorPosition();
    }
    function onInput(){
      updateCursorPosition();
    }
    

    一个主要的现象就是,文字输入完成,移动光标到某个字后面,emoji 表情就会插入到文字的最后,这时候我再移动光标,再插入 emoji,貌似位置以正确了

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2354 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 12:35 · PVG 20:35 · LAX 05:35 · JFK 08:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.