012 配置tabBar导航菜单与opentype跳转差异

iconfont-阿里巴巴矢量图标库

pages.json

{
    "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
        {
            "path": "pages/index/index",
            "style": {
                "navigationBarTitleText": "首页"
            }
        },
        {
            "path" : "pages/list/list",
            "style" : 
            {
                "navigationBarTitleText" : "新闻列表",
                "navigationBarBackgroundColor": "#5ada66",
                "navigationBarTextStyle": "white"
            }
        },
        {
            "path" : "pages/about/about",
            "style" : 
            {
                "navigationBarTitleText" : "关于我们"
            }
        }
    ],
    
    // 如果pages中没有设置,那么使用此全局设置
    "globalStyle": {
        "navigationBarTextStyle": "black",
        "navigationBarTitleText": "uni-app",
        "navigationBarBackgroundColor": "#F8F8F8",
        "backgroundColor": "#F8F8F8"
    },
    "uniIdRouter": {},
    
    "tabBar": {
        "color": "#333",
        "selectedColor": "#15FF9",
        "list": [
            {
                "text": "首页",
                "pagePath": "pages/index/index",
                "iconPath": "static/images/tabbar/home.png",
                "selectedIconPath": "static/images/tabbar/home-h.png"
            },
            {
                "text": "列表",
                "pagePath": "pages/list/list",
                "iconPath": "static/images/tabbar/list.png",
                "selectedIconPath": "static/images/tabbar/list-h.png"
            },
            {
                "text": "我们",
                "pagePath": "pages/about/about",
                "iconPath": "static/images/tabbar/user.png",
                "selectedIconPath": "static/images/tabbar/user-h.png"
            }
        ]
    }
}

index.vue

<view>
      <navigator url="/pages/list/list" open-type="reLaunch">新闻列表</navigator>
      <navigator url="/pages/about/about">关于我们</navigator>
      <navigator url="/pages/list/list">
          <image src="../../static/images/pic2.jpg"></image>
      </navigator>
</view>

### 在 UniApp 中实现页面跳转UniApp 开发环境中,页面跳转机制微信小程序相似,但存在一些细微差别。对于页面跳转功能的支持主要体现在几个核心方法上。 #### 使用 `uni.navigateTo` 打开新页面 此方法用于保留当前页面并跳转至指定的应用内非 tabBar 页面,在栈中新增一个实例[^1]。 ```javascript uni.navigateTo({ url: 'pages/targetPage/targetPage' }); ``` #### 使用 `uni.redirectTo` 替换当前页面 该方法会关闭当前页面,并跳转到应用内的某个页面,不会增加新的历史记录条目。 ```javascript uni.redirectTo({ url: 'pages/newPage/newPage' }); ``` #### 使用 `uni.switchTab` 跳转TabBar 页面 仅适用于带有底部导航栏的目标页面,即配置文件中定义过的 tabBar 页面之一。 ```javascript uni.switchTab({ url: '/pages/tabBar/home/home' // 应为 tabBar 页面路径 }); ``` #### 使用 `uni.reLaunch` 关闭所有页面重新加载目标页面 这种方法将关闭所有打开的页面,并进入指定的新页面,通常用于登录后的首页重定向场景。 ```javascript uni.reLaunch({ url: 'pages/index/index' }); ``` 除了上述 API 方法外,还可以借助 `<navigator>` 组件来简化页面间的链接操作,允许更灵活地设置样式和交互效果。 ```html <navigator url="/path/to/page" open-type="navigate">前往某页</navigator> ``` 需要注意的是,虽然大部分情况下这些跳转逻辑可以直接沿用自微信小程序项目,但在某些特定场合下仍需注意两者间存在的差异性处理[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

懂营养的程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值