【关键字】
子窗口 / 创建 / 传递数据 / page
【问题描述】
创建子窗口过程中,如何传递数据给page3。
示例代码如下:
let errCode: number = err.code;
if (errCode) {
console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
return;
}
sub_windowClass = data;
sub_windowClass.setUIContent("pages/page3", (err: BusinessError) => {
let errCode: number = err.code;
if (errCode) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
})
【解决方案】
window.setUIContent不支持传递参数。如果想要传参可以用window.loadContent,通过LocalStorage传递。
-
方法一:
window.loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>)
参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#loadcontent9
-
方法二:
window.loadContent(path: string, storage: LocalStorage): Promise<void>
参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#loadcontent9-1