以前在項目中會經過ref在父子組件傳遞一些數據,可是具體ref的其餘用法並無深究,因此來了解一下ref的具體使用方法node
first:函數
<div ref="hello"> <!-- 綁定了data裏面的值並渲染到頁面--> <h1 v-model="msg">{{msg}}</h1> </div>
//在方法或者生命週期的函數中獲取數據
console.log(this.$refs.hello.innerText);
second:this
components:{node}//註冊子組件
<node ref="node">111222</node> //在表單中使用子組件並在子組件上使用ref
console.log(this.$refs.node); //在方法中經過refs獲取子組件的方法和屬性
這是獲取整個子組件的內容spa