uni-app iOS高版本(ios17)打包后使用mui.openWindow()传值,用mui.plus.webview.currentWebview()取值得到undefined

uni-app iOS高版本(ios17)打包后使用mui.openWindow()传值,用mui.plus.webview.currentWebview()取值得到undefined

使用mui的H5给项目打包套壳发现的问题,通过地址跳转到服务器mui项目

测试时发现,ios10和Android打包都没问题,且真机运行ios17没问题,但是ios17打正式包就出现undefined

mui.openWindow({
url:"xxx",
extras:{
//传入订单号orderNo    产品名称productName
viewId:1,
name:2,
orderNo:3
}
});

另一个页面取值后显示undefined

mui.plus.webview.currentWebview().orderNo  

以为是异步的问题,加了下面代码,还是undefined

var currentWebview = mui.plus.webview.currentWebview();
currentWebview.addEventListener('loaded', function() {
var orderNo = currentWebview.orderNo;
console.log(orderNo);
});

更多关于uni-app iOS高版本(ios17)打包后使用mui.openWindow()传值,用mui.plus.webview.currentWebview()取值得到undefined的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

着急,同样的问题,有解决吗

更多关于uni-app iOS高版本(ios17)打包后使用mui.openWindow()传值,用mui.plus.webview.currentWebview()取值得到undefined的实战教程也可以访问 https://www.itying.com/category-93-b0.html


在 UniApp 中,使用 mui.openWindow() 打开新页面并传递参数时,如果在新页面中使用 mui.plus.webview.currentWebview() 无法获取到传递的参数,可能是因为以下原因:

1. 参数传递方式问题

mui.openWindow() 的参数传递方式可能不正确。确保你在打开新页面时正确传递了参数。

mui.openWindow({
    url: 'newPage.html',
    id: 'newPage',
    extras: {
        key1: 'value1',
        key2: 'value2'
    }
});

2. 获取参数的方式问题

在新页面中,获取参数的方式可能不正确。确保你使用 plus.webview.currentWebview() 获取当前页面的 Webview 对象,并通过 extras 属性获取传递的参数。

var currentWebview = plus.webview.currentWebview();
var extras = currentWebview.extras;
console.log(extras.key1); // 输出: value1
console.log(extras.key2); // 输出: value2

3. iOS 17 的兼容性问题

如果你在 iOS 17 上遇到问题,可能是由于 iOS 17 对某些 Webview API 的行为进行了调整。可以尝试以下方法:

  • 使用 uni-app 的原生导航方式:尽量使用 uni-app 提供的导航方式,而不是直接使用 mui 的方法。例如:

    uni.navigateTo({
        url: 'newPage?key1=value1&key2=value2'
    });
    

    在新页面中,使用 uni.getLaunchOptionsSync()onLoad 生命周期钩子获取参数:

    export default {
        onLoad(options) {
            console.log(options.key1); // 输出: value1
            console.log(options.key2); // 输出: value2
        }
    }
回到顶部