在使用emoji表情的时候,需要在多个文字中间进行插入表情
需要使用原生获取input框(因为使用组件会被包裹一层,使用ref无法直接获取)
onSelectEmoji(emoji) {
let input = document.getElementById("input");
let startPos = input.selectionStart;
let endPos = input.selectionEnd;
let resultText =
input.value.substring(0, startPos) +
emoji.data +
input.value.substring(endPos);
input.value = resultText;
input.focus();
input.selectionStart = startPos + emoji.data.length;
input.selectionEnd = startPos + emoji.data.length;
//赋值数据
this.$set(this.form, "content", resultText);
}