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

小程序中的页面跳转

小程序中的页面跳转

在之前网页的学习中,我们往往采用超链接,或者定义方法、函数等方式来实现页面的跳转,但是微信小程序中没有超链接,那我们该如何实现呢?微信小程序的页面跳转包括两个,一个是tabBar页面的跳转,一个是非tabBar页面的跳转

1.跳转到tabBar页面

使用的代码

uni.switchTab({})
  • html代码

    <template><view><view><button>欣赏小姐姐</button></view></view>
    </template>
    
  • js代码

<script>export default {data() {return {}},methods: {// 定义跳转方法turn1() {// 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面uni.switchTab({// person.vue页面路径url: "/pages/person/person"})}}}
</script>
  • 调用方法
<template><view><view><button @click="turn1()">欣赏小姐姐</button></view></view>
</template>

完整代码:

<template><view><view><button @click="turn1()">欣赏小姐姐</button></view></view>
</template><script>export default {data() {return {}},methods: {// 定义跳转方法turn1() {// 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面uni.switchTab({// person.vue页面路径url: "/pages/person/person"})}}}
</script><style></style>
  • uni.switchTab(OBJECT)方法的具体讲解可在uni-app官网中查看,在“API”中找到“页面和路由”,再找到“uni.switchTab”

2.跳转到非tabBar页面

代码:

uni.navigateTo({})
  • html代码:
<template><view><view><button>打开新页面</button></view></view>
</template>
  • js代码:
<script>export default {data() {return {}},methods: {// 定义跳转方法turn2(){//保留当前页面,跳转到应用内的某个页面uni.navigateTo({//new.vue页面路径url:"/pages/new/new"})}}}
</script>
  • 调用方法
<template><view><view><button @click="turn2()">打开新页面</button></view></view>
</template>
  • 完整代码

    <template><view><view><button @click="turn2()">打开新页面</button></view></view>
    </template><script>export default {data() {return {}},methods: {// 定义跳转方法turn2(){//保留当前页面,跳转到应用内的某个页面uni.navigateTo({//new.vue页面路径url:"/pages/new/new"})}}}
    </script><style></style>
    
  • uni.navigateTo(OBJECT)方法的具体讲解可在uni-app官网中查看,在“API”中找到“页面和路由”,再找到“uni.navigateTo”

http://www.xdnf.cn/news/3310.html

相关文章:

  • TimeDistill:通过跨架构蒸馏的MLP高效长期时间序列预测
  • 有状态服务与无状态服务:差异、特点及应用场景全解
  • leetcode76
  • Vue+tdesign t-input-number 设置长度和显示X号
  • 智能驾驶新时代:NVIDIA高级辅助驾驶引领未来出行安全
  • iOS 性能调优实战:三款工具横向对比实测(含 Instruments、KeyMob、Xlog)
  • C语言与Unix的传奇起源
  • (32)VTK C++开发示例 ---背景纹理
  • pytorch中的变量内存分配
  • WPF之RadioButton控件详解
  • C/C++核心机制深度解析:指针、结构体与动态内存管理(面试精要)
  • 生成项目.gitignore文件的多种高效方式
  • 分布式-redisson
  • 优先级队列
  • 【DBeaver】如何连接MongoDB
  • VSCode Auto Rename Tag插件不生效
  • OLED技术解析与驱动实战指南
  • Python 使用一等函数实现设计模式(“命令”模式)
  • C++智能指针
  • Gradio全解20——Streaming:流式传输的多媒体应用(1)——流式传输音频:魔力8号球
  • AE模板 动感节奏快闪图文展示介绍片头 Typographic Intro
  • Hadoop 集群基础指令指南
  • usb端点笔记
  • 【UE5】“对不起,您的客户端未能传递登录所需的参数”解决办法
  • QCefView应用和网页的交互
  • Github 热点项目 Qwen3 通义千问全面发布 新一代智能语言模型系统
  • WPF使用高性能图表
  • 【游戏ai】从强化学习开始自学游戏ai-2 使用IPPO自博弈对抗pongv3环境
  • 基于C++的IOT网关和平台4:github项目ctGateway交互协议
  • flutter 专题 一百零四 Flutter环境搭建