layout/default.vue
:
<template>
<slot />
<div ref="elRef"></div>
<BaseComponent />
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import BaseComponent from './BaseComponent.vue'
const elRef = ref()
provide('elRef', elRef)
onMounted(() => {
console.log('elRef:', elRef.value)
})
</script>
pages/index/index.vue
<template>
<view></view>
</template>
<script setup lang="ts">
import { inject, ref } from 'vue'
const title = ref('Hello')
const elRef = inject('elRef')
onMounted(() => {
console.log('
lanxiz (作者)
刚刚发现了 当时脑子有点短路 没有想到
2024-11-28 17:04