Commit 77a60558 authored by youjie's avatar youjie
parents 0739b60b 67a80c49
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
</template> </template>
<script> <script>
export default { export default {
props: ["value", "canEdit","textLength"], props: ["value", "canEdit", "textLength"],
data() { data() {
return { return {
innerText: this.value, innerText: this.value,
...@@ -21,26 +21,22 @@ ...@@ -21,26 +21,22 @@
}, },
methods: { methods: {
changeText: function () { changeText: function () {
let sel = window.getSelection() let sel = window.getSelection();
let offset = sel.anchorOffset let offset = sel.anchorOffset;
if(this.$el.innerText.length>this.textLength){ if (this.$el.innerText.length > this.textLength) {
this.$el.innerText = this.$el.innerText.slice(0,3) 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); this.$emit("input", this.$el.innerText);
// setTimeout(() => { setTimeout(() => {
// var range = sel.getRangeAt(0); var range = sel.getRangeAt(0);
// if (range) { var textNode = range.startContainer;
// var textNode = range.startContainer; range.setStart(textNode, offset);
// if (textNode) { sel.removeAllRanges();
// range.setStart(textNode, offset) sel.addRange(range);
// } }, 0);
// if (sel) {
// 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