vue 的 ref 属性类似于id写在原生节点中得到的是节点对象;写在子组件节点中的到的是 子组件的实例对象
例如
<template>
<div>
<h1 v-text="msg" ref="title"></h1>
<button @click="showDOM" ref="btn">点击我输出上方的DOM元素</button>
<SchoolTest></SchoolTest>
</div>
</template>
import SchoolTest from './components/School.vue'
export default {
name: 'AppTest',
components: {
SchoolTest
},
data(){
return{
msg: '欢迎学习Vue',
}
},
methods: {
showDOM(){
console.log(this.$refs)
}
}
}