Commit 77a60558 authored by youjie's avatar youjie
parents 0739b60b 67a80c49
......@@ -5,7 +5,7 @@
</template>
<script>
export default {
props: ["value", "canEdit","textLength"],
props: ["value", "canEdit", "textLength"],
data() {
return {
innerText: this.value,
......@@ -21,26 +21,22 @@
},
methods: {
changeText: function () {
let sel = window.getSelection()
let offset = sel.anchorOffset
if(this.$el.innerText.length>this.textLength){
this.$el.innerText = this.$el.innerText.slice(0,3)
let sel = window.getSelection();
let offset = sel.anchorOffset;
if (this.$el.innerText.length > this.textLength) {
this.$el.innerText = this.$el.innerText.slice(0, 3);
}
if (this.textLength) {
this.$el.innerText = this.$el.innerText.slice(0, this.textLength);
}
if(this.textLength) this.$el.innerText = this.$el.innerText.slice(0,this.textLength)
this.$emit("input", this.$el.innerText);
// setTimeout(() => {
// var range = sel.getRangeAt(0);
// if (range) {
// var textNode = range.startContainer;
// if (textNode) {
// range.setStart(textNode, offset)
// }
// if (sel) {
// sel.removeAllRanges()
// sel.addRange(range)
// }
// }
// }, 0)
setTimeout(() => {
var range = sel.getRangeAt(0);
var textNode = range.startContainer;
range.setStart(textNode, offset);
sel.removeAllRanges();
sel.addRange(range);
}, 0);
}
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment