uni-app uni.showActionSheet()在一个页面点击弹出后 从推送进入 没有自动关闭
uni-app uni.showActionSheet()在一个页面点击弹出后 从推送进入 没有自动关闭
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Windows | 10 22H2 | HBuilderX |
### 操作步骤:
```javascript
// uni.showActionSheet({
// itemList: ['修改', '删除'],
// success: (res) => {
// if(res.tapIndex===0){
// uni.navigateTo({url:'/pages/work/fire/editVideo'+uni.$u.queryParams(this.curVideo)})
// }else if(res.tapIndex===1){
// uni.showModal({
// title: '确认删除该过程视频么?',
// confirmText: "确认",
// success: (res)=> {
// if (res.confirm) {
// removeWorkDevice(this.curVideo.id).then(res=> {
// this.$u.toast('删除成功');
// })
// }
// }
// });
// }
// },
// });
预期结果:
从推送进入理应关闭
实际结果:
uni.showActionSheet未关闭
bug描述:
【报Bug】uni.showActionSheet()在一个页面点击弹出后,从推送进入,没有自动关闭。且没有提供关闭方法。
1 回复
在 uni-app 中,uni.showActionSheet()
是一个用于显示操作菜单的 API。如果你在页面中点击弹出操作菜单后,通过推送进入其他页面,操作菜单可能不会自动关闭。这是因为 uni.showActionSheet()
是一个模态弹窗,它不会自动随着页面切换而关闭。
要解决这个问题,你可以在页面切换或推送进入其他页面时,手动关闭操作菜单。你可以通过以下方式实现:
1. 在页面生命周期钩子中关闭操作菜单
你可以在页面的 onHide
或 onUnload
生命周期钩子中调用 uni.hideToast()
来关闭操作菜单。
export default {
onHide() {
uni.hideToast(); // 关闭操作菜单
},
onUnload() {
uni.hideToast(); // 关闭操作菜单
}
}
2. 在推送进入其他页面时关闭操作菜单
如果你是通过 uni.navigateTo
或 uni.redirectTo
等 API 进行页面跳转,你可以在跳转之前手动关闭操作菜单。
uni.showActionSheet({
itemList: ['选项1', '选项2'],
success: function (res) {
console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
},
fail: function (res) {
console.log(res.errMsg);
}
});
// 在跳转页面之前关闭操作菜单
uni.navigateTo({
url: '/pages/otherPage',
complete: function() {
uni.hideToast(); // 关闭操作菜单
}
});
3. 使用全局事件监听
你可以在全局监听页面切换事件,并在事件触发时关闭操作菜单。
// 在 App.vue 中监听页面切换事件
export default {
onLaunch() {
uni.onAppRoute((res) => {
uni.hideToast(); // 关闭操作菜单
});
}
}
4. 使用 Promise
或 async/await
如果你使用的是 Promise
或 async/await
,你可以在页面跳转之前等待操作菜单关闭。
async function showActionSheetAndNavigate() {
await uni.showActionSheet({
itemList: ['选项1', '选项2'],
success: function (res) {
console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
},
fail: function (res) {
console.log(res.errMsg);
}
});
uni.navigateTo({
url: '/pages/otherPage'
});
}