uniapp input 光标出现在文本末尾
进坑三天,终于第四天爬坑,多亏下面一篇博文启发
https://blog.csdn.net/nailgo/article/details/100134765
<input type="text" @click="focusEnd" ref="input" />
focusEnd (e) {
var input = that.$refs.input.$refs.input
var length = input.value.length
if (input.setSelectionRange) {
input.focus()
// focus方法是个异步的
this.$nextTick(() => {
input.setSelectionRange(length,length);
});
} else if (input.createTextRange) {
const range = input.createTextRange()
range.collapse(true)
range.moveEnd('character', length)
range.moveStart('character', length)
range.select()
}
}```