Vue ref获取vue组件dom,默认选中input中的值

如果获取的是vue组件,获取到的会是组件最外层的dom,
这是我获取vant的input组件所获取到的值:

 <van-field
   ref="input"
   id="input"
   v-model="money"
   type="number" />

console.log(this.$refs.input)  // 只能获取到外层组件dom
console.log(document.getElementById('input')) // 获取dom

Vue ref获取vue组件dom,默认选中input中的值_第1张图片
在这里插入图片描述
打开选中input中的值

setTimeout(() => {
     
  document.getElementById('input').select()   //window.select()  选中window中的值 
}, 100)

Vue ref获取vue组件dom,默认选中input中的值_第2张图片

你可能感兴趣的:(Vue ref获取vue组件dom,默认选中input中的值)