当前位置: 首页 > news >正文

解决 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                       
http://www.lryc.cn/news/380895.html

相关文章:

  • Jenkins nginx自动化构建前端vue项目
  • Devicetree - 删除某个节点或属性
  • Xcode will continue when the operation completes
  • Python爬虫-贝壳新房
  • Canvas绘制图片和区域
  • Day10—Spark SQL基础
  • 开源技术:在线教育系统源码及教育培训APP开发指南
  • [C++][设计模式][观察者模式]详细讲解
  • Adobe Acrobat 编辑器软件下载安装,Acrobat 轻松编辑和管理各种PDF文件
  • eVTOL飞机:技术挑战、应用机遇和运动的作用
  • 【python】flask中如何向https服务器传输信息
  • 计算机网络 —— 应用层(FTP)
  • zookeeper + kafka消息队列
  • Python高级编程:深度学习基础
  • 如何从magento1迁移到magento2
  • 【Nginx】Nginx安装及简单使用
  • 【Linux系列】find命令使用与用法详解
  • Apple - DNS Service Discovery Programming Guide
  • 如何高效地为pip换源:详细操作指南
  • 免费ddns工具,快解析DNS解析使用教程
  • 【Vite】控制打包结构
  • Debian Linux安装minikubekubectl
  • Discuz动漫二次元风格网站模板
  • RIP、OSPF、IS-IS学习
  • 移植案例与原理 - build lite源码分析 之 hb命令__main__.py
  • Leo赠书活动-26期 不同数据库背后的数据存储方案
  • 在Windows10中使用Vim
  • 【Python机器学习实战】 | 基于PCA主成分分析技术读入空气质量监测数据进行数据预处理并计算空气质量综合评测结果
  • 学习java第一百零八天
  • Linux通配符总结