跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

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

发表于

就像 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,貌似位置以正确了

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.