HarmonyOS学习之路由实现界面跳转

HarmonyOS学习之路由实现界面跳转

在阿里的icon库中下载相应图标

在这里插入图片描述
搞定最下面的图标之后,进行路径的配置
首先导入路由模块:

import router from '@system.router';

导入后进行函数的编写,利用router.push(OBJECT)完成界面的跳转
在这里插入图片描述

具体代码

如下:
tabbar.hml

<div class="container">
    <toolbar class="tabbar">
        <toolbar-item for="{{tabbarItems}}" icon='{{$item.img}}' value='{{$item.name}}' onclick="jump($idx)" ></toolbar-item>
    </toolbar>
</div>

tabbar.css

.tabbar {
    position: fixed;
    left: 0;
    bottom: 0;
}

tabbar.js

import tabbarItems from '../../common/datas/tabbarItems.js';
import router from '@system.router';
export default {
    data:{
        tabbarItems
    },
    props:{
      index:{
          type:Number,
          default(){
              return 0;
          }
      }
    },
    jump(index){
        switch(index){
            case 0:
            router.push({
                uri:"pages/index/index",
                params:{
                    info:"传递了一个参数"
                }
            });
            break;
            case 1:
                router.push({
                    uri:"pages/news/news",
                    params:{
                        info:"传递了一个参数"
                    }
                });
                break;
            case 2:
                router.push({
                    uri:"pages/about/about",
                    params:{
                        info:"传递了一个参数"
                    }
                });
                break;
            case 3:
                router.push({
                    uri:"pages/me/me",
                    params:{
                        info:"传递了一个参数"
                    }
                });
                break;


        }
    }
}

在其他界面引入导航栏即可,如:

<element name='comp' src='../../components/tabbar/tabbar.hml'></element>
<div class="container">
    <text class="title">
        首页
    </text>
    <text>{{info}}</text>
    <comp index="0" ></comp>
</div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值