js_reverse/学习VUE/hello_vue3/笔记/ref属性来获取组件或DOM元素的引用子.vue
2024-10-31 17:55:51 +08:00

35 lines
539 B
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="person">
<h1>中国</h1>
<h2 ref="title2">苏州</h2>
<button @click="showLog">点我输出</button>
</div>
</template>
<script setup>
import {ref, defineExpose} from "vue";
// 创建一个title2用于存储ref标记的内容
let title2 = ref()
let a = ref()
let b = ref()
let c = ref()
function showLog(){
console.log(title2.value)
}
defineExpose({a, b, c})
</script>
<style scoped>
.person {
background-color: antiquewhite;
box-shadow: 0 0 10px;
}
button {
margin: 5px;
}
</style>