vue $refs 基本用法:返回 一個(gè) 對象 ,包括注冊過 【ref 特性】的 所有dom元素 和 組件實(shí)例。
<!-- `vm.$refs.p` will be the DOM node -->
<p ref="p">hello</p>
<!-- `vm.$refs.child` will be the child component instance -->
<child-component ref="child"></child-component>
調(diào)用列子:
<input ref="input1" ></input>
<button @click="add"></button>
new Vue({
el: "#app",
methods:{
add:function(){
this.$refs.input1.value ="22"; //this.$refs.input1 減少獲取dom節(jié)點(diǎn)的消耗
}
}
})