小程序wepy代碼篇

底部導(dǎo)航欄

1.添加相應(yīng)的圖片資源

bar圖片

2.創(chuàng)建一個tab.wpy

<style type="scss">
    .tab {
        color: #7b7b7b;
        position: fixed;
        bottom: 0;
        height: 98rpx;
        width: 100%;
        border-top: 1px solid #dad9d6;
        background-color: #f7f7f7;
        display: flex;
        flex-direction: row;
        .tab_item {
            &.active {
                color: #3761ad;
            }
            height: 100%;
            flex: 1;
        }
        .icon {
            padding-top: 10rpx;
            width: 44rpx;
            height: 44rpx;
            display: block;
            margin: auto;
        }
        .title {
            text-align: center;
            font-size: 24rpx;
            padding-top: 6rpx;
            display: block;
        }
    }
</style>

<template>
    <view class="tab">
        <view class="tab_item tab_home{{active == 0 ? ' active' : ''}}" @tap="change(0)">
            <image class="icon" src="../images/bar/home{{active == 0 ? '_selected' : '_normal'}}.png" />
            <text class="title">首頁</text>
        </view>
        <view  class="tab_item tab_me{{active == 1 ? ' active' : ''}}" @tap="change(1)">
            <image class="icon" src="../images/bar/me{{active == 1 ? '_selected' : '_normal'}}.png"/>
            <text class="title">我</text>
        </view>
    </view>
</template>
<script>
  import wepy from 'wepy'
  export default class Tab extends wepy.component {
    props = {
      active: {
        twoWay: true
      }
    }
    data = {
    }
    methods = {
      change (idx, evt) {
        this.active = +idx
      }
    }
    onLoad () {
    }
  }
</script>

3.在index.wpy中添加

<tab :active.sync="currentTab" />

4.運行結(jié)果

底部導(dǎo)航欄添加完成
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容