<template>
<div>
<h1 ref="hRef">啊啊啊啊啊啊</h1>
<Demo ref="dRef"/>
</div>
</template>
<script>
import Demo from './Demo.vue'
import { ref, onMounted } from 'vue'
export default {
components: {
Demo,
},
setup() {
// 创建一个空的ref
const hRef = ref(null)
const dRef = ref(null)
onMounted(() => {
console.log(hRef.value.innerHTML)
cosnole.log(dRef.value)
})
}
}
</script>
总结: 创建一个空的ref,并且把这个变量给到模板上的ref,使得他们之间产生联系,