uniapp的两个跳转方式

简介: 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()
              }
相关文章
|
1月前
|
JavaScript 数据安全/隐私保护 UED
UniApp 中的路由魔法:玩转页面导航与跳转
UniApp 中的路由魔法:玩转页面导航与跳转
399 3
|
1月前
uniapp Vue3 日历 可签到 跳转
uniapp Vue3 日历 可签到 跳转
36 0
|
1月前
|
JavaScript
uniapp+vue3路由跳转传参
uniapp+vue3路由跳转传参
184 0
|
1月前
|
Web App开发 小程序 Android开发
Uniapp 底部导航栏 自定义 tabBar 全端 全页面引用跳转 组件
Uniapp 底部导航栏 自定义 tabBar 全端 全页面引用跳转 组件
102 0
|
1月前
|
开发框架 移动开发 Android开发
uniapp的几种跳转方式
uniapp的几种跳转方式
|
11月前
|
小程序
小程序-uniapp:实现锚点连接/锚点跳转
小程序-uniapp:实现锚点连接/锚点跳转
446 0
|
1月前
uniapp 实现带参数跳转页面
uniapp 实现带参数跳转页面
39 0
|
7月前
uniapp带参数跳转,新页面接收参数
uniapp带参数跳转,新页面接收参数
129 0
|
6月前
|
JSON JavaScript 数据格式
vue_uniapp跳转页面传递参数
本章节主要是讲解在vue跳转页面时候怎么传递参数。最后会发上实现源代码。
51 1
|
1月前
|
JavaScript
uniapp 跳转外部链接
uniapp 跳转外部链接

相关实验场景

更多