• uni-app自定义底部tabBar导航适配机型


    1.首先需要在page.json里把

    "tabBar": {
            "custom": true
    }
    在app.vue中读取机型的屏幕高度 设置一个全局变量 tbBottom
     globalData: {
        //全局变量 
        tbBottom:0,
      },
     onLaunch: function () {
        let wxSync=wx.getSystemInfoSync();
    this.globalData.tbBottom=wxSync.screenHeight-wxSync.safeArea.bottom
      },
    然后就是组件封装 props的selectIndex用来确定哪一个按钮是选中的状态
    <template>
      <div class="tabbar" :style="{'bottom':tbBottom+'px'}">
        <ul>
          <li v-for="(item, index) in pageData" :key="index" @click="goPage(item.pagePath)">
            <img :src="selectIndex==index?item.selectedIconPath:item.iconPath" alt="" />
            <p>{{ item.text }}</p>
          </li>
        </ul>
      </div>
    </template>
    <script>
    export default {
      props:['selectIndex'],
      data() {
        return {
          tbBottom: getApp().globalData.tbBottom,
          pageData: [
            {
              text: "首页",
              pagePath:'/pages/index/index',
              iconPath: "/static/home.png",
              selectedIconPath:'/static/home_se.png'
            },
            {
              text: "个人",
               pagePath:'/pages/service/index',
              iconPath: "/static/check.png",
              selectedIconPath:'/static/check_se.png'
            },
          ],
        };
      },
      onLoad() {},
      methods: {
        goPage(pagePath){
    
         wx.switchTab({
                            url:pagePath,
                          });
        }
      },
    };
    </script>
    <style lang="scss" scoped>
    .tabbar{
      position: fixed;
      left: 0;
      bottom: 0;
      z-index: 9;
         750rpx;
        height: auto;
        ul{
           height: auto;
           100%;
          display: flex;
          justify-content: space-between;
           align-items: center;
          li{
            flex: 1;
            height: 120rpx;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            img{
              height: 80rpx;
               80rpx;
      
            }
          }
        }
    
        
    }
    </style>

    如:在index.vue页面中

    给selectIndex传0进去 就显示选中第一个

  • 相关阅读:
    使用jedis连接redis
    布隆过滤器redis缓存
    SQL与NOSQL
    Charles 移动端抓包工具,使用方法以及注意事项
    安装npm包的时候报错rollbackFailedOptional: verb npm-session
    You may need an appropriate loader to handle this file type.
    数组去重
    判断两个数组是否相等(包括数组里边的键值对是否相等)
    数组里的字符串转为数字
    背景色铺满整个屏幕
  • 原文地址:https://www.cnblogs.com/huangla/p/15498171.html
Copyright © 2020-2023  润新知