当前位置:网站首页>【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>
边栏推荐
- Teach you to learn dapr - 1 The era of net developers
- Redis 概述整理
- [suggested collection] 11 online communities suitable for programmers
- Screenshot of the answers to C language exercises
- Play with Linux and easily install and configure MySQL
- Necessary decorator mode for 3 years' work
- proxy
- Cache breakdown! Don't even know how to write code???
- Count the number of words in a line of string and take it as the return value of the function
- 对NFT市场前景的7个看法
猜你喜欢

【推荐系统学习】推荐系统架构

Summary of all knowledge points of C language

ACL 2022 | 基于神经标签搜索的零样本多语言抽取式文本摘要

Getting started with mongodb

Teach you to learn dapr - 8 binding

建立自己的网站(16)

SIGIR 2022 | University of Hong Kong and others proposed the application of hypergraph comparative learning in Recommendation System

经典同步问题

Platform management background and merchant menu resource management: merchant registration management design

MySQL index
随机推荐
Basic requirements: 7 problems in singleton mode
Cloud native 02: Alibaba cloud cloud efficient flow pipeline
Use FST JSON to automatically generate faster JSON serialization methods
Here comes the hero League full skin Downloader
Use middleware to record slow laravel requests
Daily record 2
Today, I met a "migrant worker" who took out 38K from Tencent, which let me see the ceiling of the foundation
Day10 daily 3 questions (1): sum gradually to get the minimum value of positive numbers
Teach you to learn dapr - 8 binding
Web3去中心化存储生态图景
Teach you to learn dapr - 4 Service invocation
【万字总结】以终为始,详细分析高考志愿该怎么填
LeetCode Algorithm 24. Exchange the nodes in the linked list in pairs
The latest masterpiece of Alibaba, which took 182 days to produce 1015 pages of distributed full stack manual, is so delicious
Distributed Architecture Overview
MySQL index
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)
Problems encountered this week
Swap two numbers
Some explanations for latex CJK