//ref属性
//1、被用来给子组件或html标签注册引用信息
//2、用在html标签上是获取真实DOM元素,用在子组件上是组件的实例对象(vc)
<template>
<div>
<h2 ref="title">标题</h2>
<button @click="showDOM" ref="btn">点我输出上方的DOM元素</button>
<School ref="sch"></School>
</div>
</template>
<script>
import School from "./components/School.vue";
export default {
name: "App",
components: { School },
methods: {
showDOM() {
console.log(this.$refs.title); //真实的DOM元素
console.log(this.$refs.btn); //真实的DOM元素
console.log(this.$refs.sch); //获取组件的实例对象VueComponent
},
},
};
</script>
<style>
</style>
ref属性
- 本文链接: http://lzkpersonal.com.cn/2023/06/25/1-ref属性/
- 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!