1***@qq.com
1***@qq.com
  • 发布:2025-10-30 11:44
  • 更新:2025-10-30 11:44
  • 阅读:21

vue3使用uni.navigateTo设置events监听,收不到下级页面的消息

分类:HBuilderX

我的需求是在A页面展示一些用户信息之类的,如果点击某个view,我会判断用户是否登录了,没登录就跳转B登录页面,在登录页登录成功之后。告诉A页面,然后跳转回去,现在遇到的问题是,B级页面发送信息之后,A页面收不到,我打印B级页面的eventChannel,显示下面的内容,求大神解惑

{  
    "id": 7,  
    "listener": {},  
    "emitCache": [{  
        "eventName": "loginRes",  
        "args": [{  
            "result": true  
        }]  
    }]  
}

这是我A级页面的代码:

// 查看用户登录状态  
    const checkUserStatus = () => {  
        if (!user.isLoggedIn) {  
            uni.navigateTo({  
                url: "/pages/login/login",  
                events:{  
                    loginRes:function(data){  
                        console.log(data);  
                      if(data.result){  
                          // 登录成功,更新用户信息  
                         updateUserInfo();  
                      }  
                    }  
                }  
            })  
        }  
        return user.isLoggedIn;  
    }

这是我B级页面的代码

const instanceRef = ref(null);  
import {  
        getCurrentInstance,  
        ref  
    } from 'vue';  
import {  
        onLoad,  
        onUnload  
    } from '@dcloudio/uni-app'  

// 获取用户信息  
    const onGetUserInfo = async () => {  
        try {  
            let res = await apiGetUserInfo();  
            const eventChannel = instanceRef.value.proxy.getOpenerEventChannel();  
            console.log(eventChannel);  
            eventChannel.emit('loginRes', {  
                result: true  
            });  
            // 此处后续需要加入IM  
            uni.navigateBack();  
        } catch (error) {  
            console.log(error);  
            uni.showToast({  
                title: "获取用户信息失败",  
                icon: 'fail'  
            })  
        } finally {  
            uni.hideLoading();  
        }  
    }  
    onLoad(() => {  
        instanceRef.value = getCurrentInstance();  
    })
2025-10-30 11:44 负责人:无 分享
已邀请:

要回复问题请先登录注册