就像 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,貌似位置以正确了
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.