父页面:
const jumpUrl = /pages/doodleEdit/index?index=${index}&data=${jsonString}
;
console.log("jumpToEditDoodlePage jumpUrl = " + jumpUrl);
navigateTo({
url: jumpUrl,
success: function(res) {
console.log('success res = ', res);
// 获取 EventChannel 对象
const eventChannel = res.eventChannel;
Code: Select all
// 监听来自子页面的事件,并获取数据
eventChannel.on('acceptDataFromChildPage', function(data) {
console.log('来自子页面的数据:', data);
});
},
});
子页面:
import { usePageEvent, usePageInstance} from '@ray-js/ray';
const page = usePageInstance();
usePageEvent('onLoad', (query) => {
const eventChannel = page.getOpenerEventChannel();
console.log("usePageEvent onLoad:", eventChannel);
// 当需要向父页面传递数据时
eventChannel.emit('sendDataToParent', { data: 'some data' });
});
目前consolo报错是 eventChannel.on 和eventChannel.emit 这两个方法找不到。
index.tsx:235 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'on')
at success (index.tsx:235:22)
at success (service.js?side=service:3:376036)
at service.js?side=service:3:492305
at Object.invoke (C:\Users\19195\AppData\Local\Programs\Tuya MiniApp IDE\resources\app\node_modules\@ark\miniapp-bridge\dist\electron-browser\mothra-bridge.js:1:413)
success @ index.tsx:235
success @ service.js?side=service:3
(anonymous) @ service.js?side=service:3
invoke @ C:\Users\19195\AppData\Local\Programs\Tuya MiniApp IDE\resources\app\node_modules\@ark\miniapp-bridge\dist\electron-browser\mothra-bridge.js:1
await in invoke (async)
value @ service.js?side=service:3
Af @ service.js?side=service:3
navigateTo @ service.js?side=service:3
e.navigateTo @ service.js?side=service:3
jumpToEditDoodlePage @ index.tsx:227
onClick @ index.tsx:266
handler @ createCallbackProxy.js:66
(anonymous) @ Container.js:164
batchedUpdates @ react-reconciler.development.js:14923
cbOrEventHandler @ Container.js:163
Fr @ service.js?side=service:3
value @ service.js?side=service:3
value @ service.js?side=service:3
value @ service.js?side=service:3
$emit @ basic.js:7
onClick @ index.component.js:72
Fr @ service.js?side=service:3
value @ service.js?side=service:3
i @ service.js?side=service:3
setTimeout (async)
ve.setTimeout @ service.js?side=service:3
gt @ service.js?side=service:3
(anonymous) @ service.js?side=service:3
(anonymous) @ service.js?side=service:3
value @ service.js?side=service:3
(anonymous) @ service.js?side=service:3
value @ service.js?side=service:3
(anonymous) @ service.js?side=service:3
(anonymous) @ C:\Users\19195\AppData\Local\Programs\Tuya MiniApp IDE\resources\app\node_modules\@ark\miniapp-bridge\dist\electron-browser\mothra-bridge.js:1
__handle @ C:\Users\19195\AppData\Local\Programs\Tuya MiniApp IDE\resources\app\node_modules\@ark\miniapp-bridge\dist\electron-browser\mothra-bridge.js:1
(anonymous) @ VM422:1
(anonymous) @ node:electron/js2c/renderer_init:2
(anonymous) @ node:electron/js2c/renderer_init:2
emit @ node:events:513
onMessage @ node:electron/js2c/renderer_init:2
service.js?side=service:3 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'emit')
at index.tsx:78:18
at createPageConfig.js:201:37
at batchedUpdates (react-reconciler.development.js12)
at createPageConfig.js:200:26
at Array.map (<anonymous>)
at Caches2.callLifecycle (createPageConfig.js:199:57)
at Caches2.<anonymous> (createPageConfig.js:153:34)
at step (createPageConfig.js:32:23)
at Object.next (createPageConfig.js:13:53)
at fulfilled (createPageConfig.js:4:58)