uniapp 子组件中onLoad,onShow方法不执行

uniapp中,有应用生命周期和页面生命周期,子组件没有应用周期,所有onLoad,onShow都不存在,难怪我用两个方法没有效果。

可以用如下方法:

1
2
3
4
5
6
7
8
9
// 子组件
export default {
    methods: {
        childOnShow() {
            console.log('子组件 onShow');
            // 在这里执行你需要的操作
        }
    }
}

  

1
2
3
4
5
6
// 父组件
<template>
    <view>
        <child-component ref="childComponent"></child-component>
    </view>
</template>

  

1
2
3
4
5
// 父组件
export default {
    onShow() {
        this.$refs.childComponent.childOnShow();
    }

 

posted @   想要魔法棒  阅读(4460)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示