naj12312231 2022-03-23 12:24 采纳率: 100%
浏览 26
已结题

微信小程序页面名称怎么变成tab选择器

img


如图所示
右边的名字直接用 :navigationBarTitleText 属性就可以了
但是左边那种选择器的这么才能实现呢?

  • 写回答

3条回答 默认 最新

  • ··零·· 2022-03-23 14:14
    关注

    html:

    img

    <view class="tabs">
      <view class="tab-item {{status==1?'active':''}} " bindtap="handleTab" data-status="1">我的圈子</view>
      <view class="tab-item {{status==2?'active':''}} " bindtap="handleTab" data-status="2">其他圈子</view>
    </view>
    

    CSS:

    .tabs {
        padding:0 20rpx;
        margin-top:40rpx;
        width:calc( 100% - 40rpx);
        height:80rpx;
    }
    .tab-item {
        height:60rpx;
        line-height:60rpx;
        float:left;
        position:relative;
        color:#666666;
        margin-right:20rpx;
    }
    .tab-item.active {
        color:#000000;
    }
    .tab-item.active::after {
        width:40rpx;
        height:4rpx;
        background:#000000;
        position:absolute;
        bottom:0rpx;
        left:50%;
        margin-left:-20rpx;
        content:'';
        display:block;
    }
    
    
    
    

    JS:

      /**
       * 页面的初始数据
       */
      data: {
        status:1//选中状态
      },
    
      /**
       * 生命周期函数--监听页面加载
       */
      onLoad: function (options) {
    
      },
    
      handleTab(e){
    
        this.data.status=e.currentTarget.dataset.status
        this.setData({
          status:this.data.status
        })
      },
    
    
    

    Json:

    {
      "usingComponents": {},
      "navigationStyle":"custom"
    }
    
    
    

    小程序只要用到自定义custom,不管是全局页面还是单页面(以上是单页面),都需要处理不同机型头部高度兼容。
    在app.js中

        // 获取导航高度;
        wx.getSystemInfo({
          success: res => {
            //导航高度
            this.globalData.navHeight = res.statusBarHeight * (750 / res.windowWidth) + 97;
          }, fail(err) {}
        });
        
      globalData: {
        navHeight: 0,
    
      },
    

    单页中的js调用全局导航高度,处理自定义头部导航的高度

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 4月28日
  • 已采纳回答 4月20日
  • 创建了问题 3月23日

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程