<template>
<div>
<!-- 定义ref -->
<p ref="testRef">ref测试</p>
<button @click="show">使用ref</button>
</div>
</template>
<script>
export default {
name: "RefDemo",
methods: {
show(){
//html标签上获取的是真实DOM元素,应用在组件标签上是组件实例对象
console.log(this.$refs.testRef)
}
}
}
</script>
Vue 组件ref的基本使用
最新推荐文章于 2023-08-06 22:31:00 发布