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

49 lines
726 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.

<script setup lang="ts">
import Person from './components/Person.vue'
import {ref} from "vue";
// 创建一个ren用于存储ref标记的内容
let ren = ref()
function showLog(){
console.log(ren.value)
}
</script>
<template>
<main>
<Person ref="ren" />
<button @click="showLog">点ren我输出</button>
</main>
</template>
<style scoped>
header {
line-height: 1.5;
}
.logo {
display: block;
margin: 0 auto 2rem;
}
@media (min-width: 1024px) {
header {
display: flex;
place-items: center;
padding-right: calc(var(--section-gap) / 2);
}
.logo {
margin: 0 2rem 0 0;
}
header .wrapper {
display: flex;
place-items: flex-start;
flex-wrap: wrap;
}
}
</style>