当前位置:网站首页>【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>
边栏推荐
- Platform management background and merchant menu resource management: Design of platform management background data service
- [C language] static modifies local variables
- y=1/100*100+1/200*200+1/300*300+.....+ 1/m*m
- Teach you to learn dapr - 2 Must know concept
- Some explanations for latex CJK
- Notes on flowus
- 建立自己的网站(16)
- ACL 2022 | zero sample multilingual extracted text summarization based on neural label search
- Swap two numbers
- 去中心化NFT交易协议将击败OpenSea
猜你喜欢
Incomplete line spacing adjustment of formula display in word
数字藏品与NFT到底有何区别
Introduction to minimal API
Turtle cartography
The latest masterpiece of Alibaba, which took 182 days to produce 1015 pages of distributed full stack manual, is so delicious
防火 疏散 自救…这场安全生产暨消防培训干货满满!
vue--vuerouter缓存路由组件
Jouer avec Linux et installer et configurer MySQL facilement
When I was in the library, I thought of the yuan sharing mode
Redis and database data consistency
随机推荐
分布式架构概述
Detailed contract quantification system development scheme and technical description of quantitative contract system development
Microservice architecture practice: business management background and SSO design: SSO design
分布式缓存/缓存集群简介
Calculate the average of N numbers in the index group of X, and return the number that is less than the average and closest to the average through formal parameters
Deployment and operation of mongodb partitioned cluster
Strength and appearance Coexist -- an exclusive interview with Liu Yu, a member of Apache pulsar PMC
She said she was tired! So tired! I want to change my career
【推荐系统学习】推荐系统架构
Discover K8E: minimalist kubernetes distribution
MySQL index
Classical synchronization problem
Redis' 43 serial cannons, try how many you can carry
num[i]++
The latest masterpiece of Alibaba, which took 182 days to produce 1015 pages of distributed full stack manual, is so delicious
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)
Day10 daily 3 questions (1): sum gradually to get the minimum value of positive numbers
Quantitative contract system development analysis case - detailed explanation of contract quantitative system development scheme
Gui+sqlserver examination system
R329 (maix-ii-a (M2A) data summary