当前位置:网站首页>【uniapp】uniapp手机端使用uni.navigateBack失效问题解决
【uniapp】uniapp手机端使用uni.navigateBack失效问题解决
2022-06-26 16:54:00 【奄奄一息的一条咸鱼】
项目所用的技术:
uniapp手机端底部的导航栏用的是colorUI中自定义的,并不是uniapp中原生的tabbar
目前问题:
点不同的tabbar可以显示不同的UI页面,关键是页面UI都在一个URL地址中,也就是说不管切换到哪个tabbar,显示的都是根路径: /。
目前需求:
需要实现在一个订单成功的页面,点击 < 后退两个页面到商城列表页,且底部要显示对应高亮的tabbar,用的uni.navigateBack没有效果,具体原因现在还不太清楚。
用了this.$router.go(-2)在浏览器模拟端实现没问题,但是打包到手机上还是不行,如下图:
于是开启了漫无目的的找bug,试解决方法…
后面发现用uniapp的uni.$emit()触发全局自定义事件,可以把要携带的参数写到对象中,然后再用uniapp的uni.$once()监听全局的自定义事件,事件由 uni.$emit 触发,但仅触发一次,在第一次触发之后移除该监听器

然后再通过uni.navigateTo进行页面跳转,就可以实现这个需求了
具体代码实现:
<script>
// 订单成功页面
export default {
name: 'orderSuccess',
methods: {
gotoMall() {
// 去往商城页,这里用uni.navigateBack会失效
// this.$router.go(-2) 该方法在浏览器端模拟没问题,但到手机上就有问题了
uni.$emit('changeBar', {
// 带上所需的 mall 字段
paramsName: "mall"
})
uni.navigateTo({
// 直接跳转到首页(首页中已经做了tabbar商城图标的高亮显示)
url: '/pages/index/index'
})
},
}
}
</script>
<script>
// 首页
export default {
onShow() {
// 全局监听uni.$emit传过来的参数
uni.$once('changeBar', function(data) {
// 说明:只要PageCur的值修改为 mall,首页中底部的tabbar商城图标就会高亮显示
this.PageCur = data.paramsName
console.log('监听到事件来自 changeBar ,携带参数为:' + data.paramsName);
})
}
}
</script>
边栏推荐
- Programmer's essential toolkit, please collect!
- Army chat -- registration of Registration Center
- MySQL index
- Platform management background and merchant menu resource management: Design of platform management background data service
- Notes on flowus
- 宝藏又小众的CTA动画素材素材网站分享
- Interpretation of new plug-ins | how to enhance authentication capability with forward auth
- Community ownership of NFT trading market is unstoppable
- The high concurrency system is easy to play, and Alibaba's new 100 million level concurrent design quick notes are really fragrant
- 分布式缓存/缓存集群简介
猜你喜欢

Strength and appearance Coexist -- an exclusive interview with Liu Yu, a member of Apache pulsar PMC

Jouer avec Linux et installer et configurer MySQL facilement

No manual prior is required! HKU & Tongji & lunarai & Kuangshi proposed self supervised visual representation learning based on semantic grouping, which significantly improved the tasks of target dete

20: Chapter 3: develop the pass service: 3: get through the redis server in the program; (it only connects with the redis server and does not involve specific business development)

Classical synchronization problem

Turtle cartography
![[suggested collection] 11 online communities suitable for programmers](/img/6b/d5c68e93384fd314d0cb27d9df1cb9.jpg)
[suggested collection] 11 online communities suitable for programmers

Basic requirements: 7 problems in singleton mode

经典同步问题

Programmer's essential toolkit, please collect!
随机推荐
In those years, interview the abused red and black trees
防火 疏散 自救…这场安全生产暨消防培训干货满满!
Kubernetes essential tools: 2021
ACL 2022 | 基于神经标签搜索的零样本多语言抽取式文本摘要
Summary of all knowledge points of C language
Here comes the hero League full skin Downloader
【万字总结】以终为始,详细分析高考志愿该怎么填
量化合约系统开发分析案例丨合约量化系统开发方案详解
Decentralized NFT transaction protocol will defeat opensea
Alibaba's "high concurrency" tutorial "basic + actual combat + source code + interview + Architecture" is a god class
Distributed Architecture Overview
Secrets of gear contract
Day10 daily 3 questions (2): count the number of the largest groups
What is the preferential account opening policy of securities companies now? Is it safe to open an account online now?
数字藏品与NFT到底有何区别
Teach you to learn dapr - 4 Service invocation
Deployment and operation of mongodb partitioned cluster
num[i]++
Detailed explanation of browser storage methods: the origin and difference of cookies, localstorage and sessionstorage
Incomplete line spacing adjustment of formula display in word