在Vue做项目时,做了一个div[contenteditable=true]的组件作为文本输入框
在非手动输入值后,光标会丢失,经测试以下这段代码可用,直接将光标定位到最后
this.$refs.editDiv.focus()
document.execCommand('selectAll', false, null);
document.getSelection().collapseToEnd();
在Vue做项目时,做了一个div[contenteditable=true]的组件作为文本输入框
在非手动输入值后,光标会丢失,经测试以下这段代码可用,直接将光标定位到最后
this.$refs.editDiv.focus()
document.execCommand('selectAll', false, null);
document.getSelection().collapseToEnd();