#2020征文-手机鸿蒙js开发二:鸿蒙js自定义底部菜单栏和三元运算

发布于 2021-1-13 16:50
815浏览
0收藏

#2020征文-手机鸿蒙js开发二:鸿蒙js自定义底部菜单栏和三元运算

<div  class="firstview">

    <!--底部菜单栏 鸿蒙必须嵌套到父的视图容器start-->
    <div  class="bottommenuview">
        <block  for="{{menus}}">
            <div  class="cellmenu"  onclick="changemenu({{$idx}})">
                <div class="imgview">
                    <image class="cimg"
                            src="{{cindex==$idx?$item.img1:$item.img2}}">
                    </image>
                </div>
                <div  class="txtview">
                  <text class="{{cindex==$idx?'a':'b'}}">{{$item.text}}</text>
                </div>
            </div>
        </block>
    </div>
    <!--底部菜单栏 鸿蒙必须嵌套到父的视图容器end-->

</div>
export default {
    data: {
        title: 'World',

        //定义菜单项
        menus:[{"text":"首页","img1":"./common/ones.png","img2":"./common/oneu.png"},
               {"text":"分类","img1":"./common/cs.png","img2":"./common/cu.png"},
               {"text":"内容","img1":"./common/cons.png","img2":"./common/conu.png"},
               {"text":"我的","img1":"./common/mys.png","img2":"./common/myu.png"}],

        //定义一个下标
        cindex:0

    },
    changemenu(index)
    {
        console.log("当前的值为:"+index);
        //赋值
        this.cindex=index;

    }

}
.firstview{
    width: 100%;
    height: 1200px;
    background-color: deepskyblue;
}

.bottommenuview{
    width: 100%;
    height: 160px;
    border-top:5px  solid   black;
    position: fixed;
    bottom: 0px;
    left: 0px;
    background-color: powderblue;
    display: flex;
    justify-content: space-around;
    
}
.cellmenu{
    width: 22%;
    height: 90%;
    /**border: 1px  solid  red;**/
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.imgview{
    width: 80%;
    height: 50%;
   /** border:2px solid  black;**/
    display: flex;
    justify-content: center;
    align-items: flex-end;

}
.txtview{
    width: 80%;
    height: 40%;
   /** border:2px solid  green;**/
    display: flex;
    justify-content: center;
    align-items: center;
}
.a{
    color: black;
    font-size: 25px;
    font-weight: bold;

}
.b{
    color: green;
    font-size: 25px;
    font-weight: bold;
}
.cimg{
    width: 40px;
    height: 40px;
}

 

#2020征文-手机鸿蒙js开发二:鸿蒙js自定义底部菜单栏和三元运算

 

 

 

 

已于2021-1-16 20:48:22修改
2
收藏
回复
举报
回复
上传资源包
上传文件可以提高自己的声望,一次最多可上传5个文件 查看上传规则
    这个用户很懒,还没有个人简介
    帖子
    视频
    声望
    粉丝
    社区精华内容