Vue3请查看 provide和inject 用法
父路由.vue
合理运用ref属性
<template>
<div>
<router-view ref="Childmain"/>
</div>
</template>
<script>
created(){
this.$refs['Childmain'].childe()
}
</script>
调用时可能会出现报错,没猜错的话报错原因是子路由还未加载,这边建议
使用setTimeout()代码延迟5毫秒执行就行
或者使用this.nextTick(() => {})
this.$nextTick(() => {
this.$refs['Childmain'].childe()
})
----------------------------------------------------------------------------分割线-------------------------------------------------------------------
子路由.vue
<template>
<div>
</div>
</template>
<script>
export default {
data(){},
methods:{