子组件:
const getDocument =()=>{
}
父组件:
<template>
<markdownDoc ref="markdownRef"></markdownDoc>
</template>
<script>
import { ref } from 'vue'
export default {
components: {
markdownDoc
},
setup() {
//起的变量名与组件上ref的名字相同
const markdownRef = ref()
const menuItem = (e) => {
//使用
markdownRef.value.getDocument(e)
}
return {
markdownRef //必须将这个变量return,否则访问不到子组件的数据
}
}
}
</script>