我的需求是在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();
})
0 个回复