<input type="text" id="demo"> // 獲取焦點,選中里面的文字 // 1.獲取input 框的元素 var input = document.getElementById('demo') // 2.獲取input 框的值 var value = input.innerText // 3.通過setSelectionRange 選中文字 input.setSelectionRange(0, value.length)
在vue通過ref拿不到setSelectionRange方法,可能需要通過id主動獲取,並且可能需要添加異步
const input = document.getElementById(`input`);
input.focus()
setTimeout(()=>{ // 或者使用nextTick
inputList.setSelectionRange(0,this.searchLetter.length);
})
