vue中通过ref属性来获取dom的引用

ref属性可以用来获取dom的引用,它的值可以随便定义, 但是注意这个名字不要和页面中其他的ref属性名相同,获取定义的ref可以通过this.$refs.ref的名字

    <div id="app">
          <input type="text" v-model="newId" ref="inputRef">
   </div>
   <script>
      let vm = new Vue({
         el: '#app',
        data: {
        newId: ''
      },
      mounted () {
        console.log(this.$refs.inputRef);
        this.$refs.inputRef.focus()
      }
    })
 </script>    
原文地址:https://www.cnblogs.com/mushitianya/p/10507651.html