function selectText(id){
this.$nextTick(()=>{
const obj = document.getElementById(id);
// 必须把输入框类型转化为 text,否则无法选取。(ERROR:selectionStart/selectionEnd on input type=“number” no longer allowed in Chrome)
const input_type = obj.type;
obj.type = 'text';
obj.selectionStart = 0; // 选中开始位置
obj.selectionEnd = obj.value.length;// 获取输入框里的长度。
obj.type = input_type;// 获得焦点后,改回number类型
})
调用方法:
selectText ( ‘你想选中的元素的ID’ );