当前位置: 首页 > news >正文

uniapp的两个跳转方式

uniapp内置多种跳转方式,我这里介绍两个最常用的跳转,uni.navigateTo和uni.switchTab,前者为跳转到非TabBar页面,后者为跳转到TabBar页面,所谓TabBar就是底部导航栏配置的页面,例如下方的index.vue。

在pages.json中

	"tabBar": {"list": [{"pagePath": "pages/index/index","text": "首页","iconPath": "static/buliangzhu.png","selectedIconPath": "static/zhuyeliang.png"},{"pagePath": "pages/user/user","text": "个人中心","iconPath": "static/user2.png","selectedIconPath": "static/user1.png"}]},

配置成导航栏的页面无法通过navigateTo方法跳转,只能通过switchTab方法。

一、navigateTo

例如我们需要在index.vue页面里面跳转到test1.vue,test1是非tabBar页面,就给需要绑定事件的按钮添加点击事件。再在methods里面编写方法,调用uni.navigateTo

<!-- index.vue -->
<template><view class="home "><button @click="toTest1"></button></view></template><script>export default {data() {return {}},methods: {toTest1() {uni.navigateTo({url:'/pages/test1/test1'})}}}
</script>

二、switchTab

这里我们在test1页面中想点击按钮跳转到index页面


<template><view class="home "><button @click="toIndex"></button></view></template><script>export default {data() {return {}},methods: {toIndex() {uni.switchTab({url:'/pages/index/index'})}}}
</script>

如果要从成功后跳转到tabBar页面只能用switchTab

success: (res) => {console.log(res.data.status, '状态');if (res.data.status == 1) {this.msgType = 'success'this.messageText = '更新成功'this.$refs.message.open()uni.switchTab({url: '/pages/index/index'})} else {this.msgType = 'error'this.messageText = '更新失败'this.$refs.message.open()}

http://www.lryc.cn/news/159537.html

相关文章:

  • 【LeetCode】1654:到家的最少跳跃次数的解题思路 关于力扣无法return的BUG的讨论
  • Calico IP In IP模拟组网
  • 在linux上挂载windows共享目录
  • drone的简单使用
  • day 52 | 84.柱状图中最大的矩形
  • BUUCTF刷题十一道(08)
  • 快速构建基于Paddle Serving部署的Paddle Detection目标检测Docker镜像
  • SOLIDWORKS工程图自动零件序号的极致体验
  • 将ROS bag转成CSV
  • jframe生成柱状图片+图片垂直合并+钉钉机器人推送
  • 如何用J-Link仿真PY32F003系列芯片
  • # Go学习-Day10
  • vue3:5、组合式API-reactive和ref函数
  • Unity Inspector面板上显示Api
  • Redis功能实战篇之附近商户
  • selenium 自动化测试——元素定位
  • 【JMeter】 二次开发插件开发 Dubbo 接口测试插件浅析
  • 手机SSL证书认证失败是什么意思?
  • PXE网络批量装机(centos7)
  • P1104 生日
  • 计算机网络复习大纲
  • Linux:进程(概念)
  • 智能机器人:打造自动化未来的关键技术
  • 大数据(七):Pandas的基础应用详解(四)
  • 【1day】​万户协同办公平台 ezoffice未授权访问漏洞学习
  • 适配器模式:如何让不兼容的接口变得兼容
  • sentinel熔断报java.lang.reflect.UndeclaredThrowableException
  • 工业4G路由器的户外组网与无人值守场景应用
  • 中移粤港澳大湾区创新研究院、南湖研究院类脑实验室面试(部分)
  • API 自动化测试难点总结与分享