ref 用来绑定元素后获取元素对象。
<div id="app">
<input ref="inp1" >
<input ref="inp2">
<button @click="getMsg">click</button>
<button @dblclick="getMsgdbl">click</button>
</div>
vm.$refs是一个对象,包含所有的ref。
new Vue({
methods:{
getMsg(){
显示"inp1"的value值
console.log(this.$refs.inp1.value)
},
getMsgdbl(){
显示"inp2"的value值
console.log(this.$refs.inp2.value)
},
}
}).$mount("#app")