欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > 解决 uniapp h5 页面在私有企微iOS平台 间歇性调用uni api不成功问题(uni.previewImage为例)。

解决 uniapp h5 页面在私有企微iOS平台 间歇性调用uni api不成功问题(uni.previewImage为例)。

2025/6/18 20:56:29 来源:https://blog.csdn.net/weixin_43245095/article/details/139747326  浏览:    关键词:解决 uniapp h5 页面在私有企微iOS平台 间歇性调用uni api不成功问题(uni.previewImage为例)。

demo

<template><view class="content"><image class="logo" src="/static/logo.png"></image><button @click="previewImage">预览图片</button></view>
</template><script>
//打开浏览器控制台
var script = document.createElement('script');
// script.src = 'https://cdn.bootcss.com/eruda/1.5.2/eruda.min.js'
script.src = '//cdn.jsdelivr.net/npm/eruda';
script.async = true;
document.getElementsByTagName('head')[0].appendChild(script);
script.onload = function () {window.eruda.init();
};
// #ifdef H5
//import {uni} from '@dcloudio/uni-h5/dist/uni-h5.es.js'
// #endifexport default {data() {return {title: 'Hello',}},onLoad() {},methods: {previewImage() {console.log('uni.previewImage', uni.previewImage);uni.previewImage({urls: ['/static/logo.png'],fail: (err) => {console.log('err', err);uni.showToast({message: err.errMsg,icon: 'none',})},});}},
}
</script><style>
.content {display: flex;flex-direction: column;align-items: center;justify-content: center;
}.logo {height: 200rpx;width: 200rpx;margin-top: 200rpx;margin-left: auto;margin-right: auto;margin-bottom: 50rpx;
}.text-area {display: flex;justify-content: center;
}.title {font-size: 36rpx;color: #8f8f94;
}
</style>

问题

uniapp h5 页面在私有企微iOS平台 间歇性调用uni api不成功,在其他平台及设备正常。

正常调用

在这里插入图片描述

私有企微iOS平台失败

在这里插入图片描述

解决

验证发现 uni.previewImage 打印出来的api正常与失败的不一致。

正常
uni.previewImage (args = {}, ...rest) => {if (hasCallback(args)) {return wrapperReturnValue(name, invokeApi(name, fn, args, rest));}return wrapperReturnValue(name,handlePromise(new Promise((resolve, reject) => {invokeApi(name,fn,extend(args, { success: resolve, fail: reject }),rest);})));}
异常
uni.previewImage function(a){c(r.previewImage,{current:a.current,urls:a.urls,hidePreviewMenuList:a.hidePreviewMenuList},a)}
最终解决

虽然不知道问题怎么产生的,但是通过正常的api 找到了对应的源码,引入uni h5的 源码就正常了

// #ifdef H5
//解决 uniapp在私有企微ios上api调用报错的问题
import { uni } from '@dcloudio/uni-h5/dist/uni-h5.es.js';
window.uni = uni;
// #endif                       

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词