获取DOM元素,一般用document.querySelector获取这个dom节点,然后在获取input的值

但是用ref绑定之后,就不需要在获取dom节点了,直接在上面的input上绑定input1,然后$refs里面调用即可

this.$refs.input1  这样可以减少获取DOM节点的消耗

<div id="app">
    <input type="text" ref="input1"/>
    <button @click="add">添加</button>
</div>
new Vue({
    el: "#app",
    methods:{
    add:function(){
         //this.$refs.input1  减少获取dom节点的消耗
        this.$refs.input1.value ="996";
        }
    }
})

 

相关文章:

  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-11
  • 2022-12-23
猜你喜欢
  • 2021-08-21
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
相关资源
相似解决方案