【发布时间】:2022-11-24 00:05:33
【问题描述】:
我正在尝试使用 Vue3 组合 API 访问子组件中的 ref,但我不确定该怎么做。我想向 mainContentRef 添加一个滚动事件,这样我就可以执行获取请求以在父组件中获取更多数据,但我似乎无法访问父组件中的 ref 以向其添加事件侦听器
这是我的代码(由于本示例不需要,因此删除了一些部分):
<!-- MAIN COMPONENT -->
<template>
<PageWrap>
<template v-slot:content>
<MainContent>
<template v-slot:content />
</MainContent>
</template>
</PageWrap>
</template>
<script setup>
//access mainContentRef here because this is where the fetch request will be
</script>
<!-- MAIN CONTENT COMPONENT -->
<template>
<div id="main-content" ref='mainContentRef'>
<slot name='content'></slot>
</div>
</template>
<script setup>
import { defineProps, ref } from 'vue';
const mainContentRef = ref(0);
</script>
【问题讨论】:
标签: javascript vuejs3 vue-composition-api