uniapp 通过通道$on或者$once调用函数内的showModal弹窗,但是没有反应

原因分析:

在微信小程序环境里,uni.showModal(也就是你封装的 showModel)只有在页面处于前台时才弹得出来

你把监听从 uni.once 改成 uni.on 后依旧"弹不出来",根本原因并不是事件没触发,而是触发时页面已经不可见(onHide 之后)。微信小程序的原生弹窗在页面不可见时会被系统直接忽略,所以用户看不到任何提示。


解决方案:

提示:使用nextTick包裹,在下一次页面渲染前执行

复制代码
function continueRelation(data) {
		nextTick(() => {
			console.log('continueRelation', data, showModel)
			showModel({
				title: "关联配件",
				content: "是否关联配件 "+data.map(e=>e.title).join('、'),
				confirm: () => {
					const parts = data.map(e => {
						return {
							taskId: oprateId.value,
							partId: e.id,
							partName: e.title,
							partImg: e.img,
							price: e.price,
							quantity: e.num,
							amount: e.price * e.num
						}
					})
					console.log("parts", parts)
					glPjShopOrder({
						id: oprateId.value,
						partList: parts
					}).then(res => {
						if (res.code == 200) {
							showSuccess("关联成功")
							const timer = setTimeout(() => {
								oprateFn && oprateFn()
								clearTimeout(timer);
							}, 1000)
						}
					})
				},
			})
		})
	}
相关推荐
叱咤少帅(少帅)11 小时前
Uniapp开发pc端,小程序和APK
小程序·uni-app
2501_915918411 天前
iOS性能测试工具 Instruments、Keymob的使用方法 不局限 FPS
android·ios·小程序·https·uni-app·iphone·webview
2501_915918411 天前
iOS 混淆流程 提升 IPA 分析难度 实现 IPA 深度加固
android·ios·小程序·https·uni-app·iphone·webview
前端 贾公子1 天前
解决uni-app 输入框,键盘弹起时页面整体上移问题
前端·vue.js·uni-app
Muchen灬1 天前
【uniapp】(5) 创建gitee仓库并推送源码
gitee·uni-app
Muchen灬1 天前
【uniapp】(6) uniapp中使用vuex
uni-app
2501_915909062 天前
React Native 上架 App Store:项目运行与审核构建的流程
android·ios·小程序·https·uni-app·iphone·webview
李庆政3702 天前
uniapp+unicloud打包部署微信小程序
微信小程序·小程序·uni-app
2501_915909062 天前
苹果 Safari 浏览器抓包 页面刷新后的请求分析
android·前端·ios·小程序·uni-app·iphone·safari