程序员scholar 程序员scholar
首页
  • Java 基础

    • JavaSE
    • JavaIO
    • JavaAPI速查
  • Java 高级

    • JUC
    • JVM
    • Java新特性
    • 设计模式
  • Web 开发

    • Servlet
    • Java网络编程
  • Web 标准

    • HTML
    • CSS
    • JavaScript
  • 前端框架

    • Vue2
    • Vue3
    • Vue3 + TS
    • 微信小程序
    • uni-app
  • 工具与库

    • jQuery
    • Ajax
    • Axios
    • Webpack
    • Vuex
    • WebSocket
    • 第三方登录
  • 后端与语言扩展

    • ES6
    • Typescript
    • node.js
  • Element-UI
  • Apache ECharts
  • 数据结构
  • HTTP协议
  • HTTPS协议
  • 计算机网络
  • Linux常用命令
  • Windows常用命令
  • SQL数据库

    • MySQL
    • MySQL速查
  • NoSQL数据库

    • Redis
    • ElasticSearch
  • 数据库

    • MyBatis
    • MyBatis-Plus
  • 消息中间件

    • RabbitMQ
  • 服务器

    • Nginx
  • Spring框架

    • Spring6
    • SpringMVC
    • SpringBoot
    • SpringSecurity
  • SpringCould微服务

    • SpringCloud基础
    • 微服务之DDD架构思想
  • 日常必备

    • 开发常用工具包
    • Hutoll工具包
    • IDEA常用配置
    • 开发笔记
    • 日常记录
    • 项目部署
    • 网站导航
    • 产品学习
    • 英语学习
  • 代码管理

    • Maven
    • Git教程
    • Git小乌龟教程
  • 运维工具

    • Docker
    • Jenkins
    • Kubernetes
  • 算法笔记

    • 算法思想
    • 刷题笔记
  • 面试问题常见

    • 十大经典排序算法
    • 面试常见问题集锦
关于
GitHub (opens new window)
首页
  • Java 基础

    • JavaSE
    • JavaIO
    • JavaAPI速查
  • Java 高级

    • JUC
    • JVM
    • Java新特性
    • 设计模式
  • Web 开发

    • Servlet
    • Java网络编程
  • Web 标准

    • HTML
    • CSS
    • JavaScript
  • 前端框架

    • Vue2
    • Vue3
    • Vue3 + TS
    • 微信小程序
    • uni-app
  • 工具与库

    • jQuery
    • Ajax
    • Axios
    • Webpack
    • Vuex
    • WebSocket
    • 第三方登录
  • 后端与语言扩展

    • ES6
    • Typescript
    • node.js
  • Element-UI
  • Apache ECharts
  • 数据结构
  • HTTP协议
  • HTTPS协议
  • 计算机网络
  • Linux常用命令
  • Windows常用命令
  • SQL数据库

    • MySQL
    • MySQL速查
  • NoSQL数据库

    • Redis
    • ElasticSearch
  • 数据库

    • MyBatis
    • MyBatis-Plus
  • 消息中间件

    • RabbitMQ
  • 服务器

    • Nginx
  • Spring框架

    • Spring6
    • SpringMVC
    • SpringBoot
    • SpringSecurity
  • SpringCould微服务

    • SpringCloud基础
    • 微服务之DDD架构思想
  • 日常必备

    • 开发常用工具包
    • Hutoll工具包
    • IDEA常用配置
    • 开发笔记
    • 日常记录
    • 项目部署
    • 网站导航
    • 产品学习
    • 英语学习
  • 代码管理

    • Maven
    • Git教程
    • Git小乌龟教程
  • 运维工具

    • Docker
    • Jenkins
    • Kubernetes
  • 算法笔记

    • 算法思想
    • 刷题笔记
  • 面试问题常见

    • 十大经典排序算法
    • 面试常见问题集锦
关于
GitHub (opens new window)
npm

(进入注册为作者充电)

  • 原生微信小程序

  • uniapp多端开发

    • 快速入门

    • 内置组件

      • 视图容器

      • 基础内容

      • 表单组件

      • 路由页面跳转

        • 导航跳转组件
          • 1. 什么是 navigator 组件?
          • 2. navigator 组件的常用属性
            • 2.1 基本页面跳转 url
            • 2.2 跳转方式 open-type
            • 2.3 回退操作 delta
            • 2.4 设置动画效果 animation-type
          • 3. 多种跳转方式与样式配置
        • Uniapp 编程式导航
      • 媒体组件

      • 地图

      • 画布

      • 网页嵌入

      • 页面属性配置节点

      • nvue组件

      • 小程序组件

    • 扩展组件

  • 小程序开发
  • uniapp多端开发
  • 内置组件
  • 路由页面跳转
scholar
2024-10-21
目录

导航跳转组件

# 导航跳转组件

navigator 组件是 Uniapp 中用于页面跳转的组件,功能类似于 HTML 中的 <a> 标签,但只能跳转到应用内的本地页面。该组件通过配置不同的跳转方式,可以在页面之间实现导航。目标页面必须在 pages.json 中注册,才能被正确导航。

# 1. 什么是 navigator 组件?

navigator 组件用于在应用内部实现页面跳转,它支持多种跳转方式,如普通导航、重定向、切换 Tab 页等。与 API 方式跳转相比,navigator 组件在页面中更直观,可以直接通过组件属性配置实现不同的跳转效果。

使用场景

  • 页面导航:跳转到新的页面或返回之前的页面。
  • 切换 Tab 页:在多 Tab 应用中,跳转到指定的 Tab 页。
  • 回退操作:通过设置 delta 属性,返回历史中的指定层级页面。

# 2. navigator 组件的常用属性

navigator 组件提供了多种属性,用于控制跳转的目标页面、方式以及动画效果等。以下是常用属性的详细说明及使用示例。

属性名 类型 默认值 说明 平台差异说明
url String 无 应用内的跳转链接,值为相对路径或绝对路径,例如:"/pages/first/first"。 无
open-type String navigate 跳转方式,包括 navigate、redirect、switchTab、reLaunch、navigateBack。 无
delta Number 无 当 open-type 为 navigateBack 时有效,表示回退的层数。 无
animation-type String pop-in/out 设置跳转的动画效果,支持 pop-in、pop-out 等多种效果。 App 平台支持
animation-duration Number 300 动画的持续时间,单位为毫秒。 App 平台支持
hover-class String navigator-hover 设置点击时的样式,默认为点击效果类 navigator-hover。 无
hover-stop-propagation Boolean false 是否阻止祖先节点出现点击态。 微信小程序支持
hover-start-time Number 50 按住多长时间后出现点击态,单位为毫秒。 无
hover-stay-time Number 600 手指松开后,点击态保留的时间,单位为毫秒。 无
target String self 在哪个小程序目标上跳转,值为 self 或 miniProgram。 微信小程序等部分平台支持

# 2.1 基本页面跳转 url

  • 说明:设置跳转目标页面的路径,支持相对路径和绝对路径。
  • 类型:String
  • 默认值:无
<template>
  <view>
    <!-- 跳转到 pages/first/first 页面 -->
    <navigator url="/pages/first/first" hover-class="navigator-hover">
      <button>跳转到新页面</button>
    </navigator>
  </view>
</template>
1
2
3
4
5
6
7
8

# 2.2 跳转方式 open-type

  • 说明:设置跳转的方式,包括 navigate(普通跳转)、redirect(重定向)、switchTab(切换 Tab 页)等。
  • 类型:String
  • 默认值:navigate
<template>
  <view>
    <!-- 普通跳转到新页面 -->
    <navigator url="/pages/first/first" open-type="navigate">
      <button>跳转到新页面</button>
    </navigator>

    <!-- 当前页重定向到新页面 -->
    <navigator url="/pages/second/second" open-type="redirect">
      <button>重定向到当前页</button>
    </navigator>

    <!-- 切换到 Tab 页面 -->
    <navigator url="/pages/tabBar/home/home" open-type="switchTab">
      <button>切换到 Tab 页面</button>
    </navigator>
  </view>
</template>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# 2.3 回退操作 delta

  • 说明:设置回退的层数,仅当 open-type 为 navigateBack 时有效。
  • 类型:Number
  • 默认值:无
<template>
  <view>
    <!-- 回退两层页面 -->
    <navigator open-type="navigateBack" :delta="2">
      <button>回退两层页面</button>
    </navigator>
  </view>
</template>
1
2
3
4
5
6
7
8

# 2.4 设置动画效果 animation-type

  • 说明:当跳转时,可以通过该属性设置动画效果,如 pop-in、pop-out 等。仅在 App 平台有效。
  • 类型:String
  • 默认值:pop-in/out
<template>
  <view>
    <!-- 跳转时使用动画效果 -->
    <navigator url="/pages/first/first" animation-type="slide-in-right">
      <button>使用动画跳转</button>
    </navigator>
  </view>
</template>
1
2
3
4
5
6
7
8

# 3. 多种跳转方式与样式配置

以下案例展示了如何使用 navigator 组件,结合不同的跳转方式、动画效果以及点击态样式来实现页面跳转。

<template>
  <view>
    <view class="section">
      <navigator url="/pages/first/first" hover-class="navigator-hover">
        <button>跳转到新页面</button>
      </navigator>
    </view>

    <view class="section">
      <navigator url="/pages/second/second" open-type="redirect" hover-class="navigator-hover">
        <button>重定向到当前页</button>
      </navigator>
    </view>

    <view class="section">
      <navigator url="/pages/tabBar/home/home" open-type="switchTab" hover-class="navigator-hover">
        <button>切换到 Tab 页面</button>
      </navigator>
    </view>
  </view>
</template>

<style scoped>
.section {
  margin: 20px 0;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

image-20241021033203505

编辑此页 (opens new window)
上次更新: 2025/02/01, 02:18:15
多行输入框组件
Uniapp 编程式导航

← 多行输入框组件 Uniapp 编程式导航→

Theme by Vdoing | Copyright © 2019-2025 程序员scholar
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式