<template>
<div class="content-padding">
<div class="shortMessage-tag">
<!-- 插入图片的标签 -->
<img @click="handleTag" :src="require('../../../static/images/name.png')">
</div>
<div
@click="handleSelection"
@input="handleSelection"
class="shortMessage-div_input"
contenteditable="true">
<div>请输入</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
selection: null,
range: null,
textNode: null,
rangeStartOffset: null
}
},
methods: {
handleTag(e) {
const parseDom = this.parseDom(
`<img @click="handleTag" src="${require('../../../static/images/name.png')}">`
)
this.range.insertNode(parseDom)
this.range.collapse(true)
},
handleSelection() {
this.selection = getSelection()
this.range = this.selection.getRangeAt(0)
this.textNode = this.range.startContainer
this.rangeStartOffset = this.range.startOffset;},
parseDom(arg) {
var objE = document.createElement("div");
objE.innerHTML = arg;
return objE.childNodes[0];
}
}
}
</script>