input cursor position input box issues

problem


After the fuzzy search is automatically selected, the cursor is positioned at the input, to be positioned at the end.

solve

setTimeout(() => {
    let obj = this.$refs.custominput;
    let value = obj.value;
    if (document.selection) {
      var sel = obj.createTextRange();
      sel.moveStart('character', value.length);
      sel.collapse();
      sel.select();
    } else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
        obj.selectionStart = obj.selectionEnd = value.length;
    }
}, 0);

After resolving the effect is as follows:

Guess you like

Origin www.cnblogs.com/xsnow/p/11818936.html