小程序van-tabs组件运用以及小程序vant tab组件解决文字过多显示不全的问题

本文介绍了如何在小程序中使用 vant tab 组件,特别是面对文字内容过长时,通过添加 `tab-class="tab-box"` 并设置 CSS 样式 `flex: none !important;` 来避免文字被省略,确保全部内容可见。展示了未加样式和添加样式后的对比效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码如下:

<view class="con">
  <van-tabs swipeable animated tab-class="tab-box" title-active-color="#A6894E" color="#DFBF7D">
  <van-tab title="{{item.tabsName}}" wx:for="{{fatherList}}" wx:key="index" wx:for-index="index" class="tab">
    <view class="van-wraper">
      <!-- 共同css -->
      <view class="" wx:for="{{item.list}}" wx:key="idx" wx:for-index="idx" class="van-item">
        <view class="comm-left">
          <image wx:if="{{item.imgUrl}}" src='{{item.imgUrl}}'></image>
          <image wx:else src='../../static/img/no-data.png'></image>
        </view>
        <view class="comm-info">
          <view class="title">{{item.title}}</view>
        </view>
      </view>
    </view>
  </van-tab>
</van-tabs>
</view>

css代码:

.con{
  padding: 0 40rpx;
  box-sizing: border-box;
}
.tab-box{
  flex: none !important;
}
.van-wraper .van-item{
  display:flex;
  justify-content: flex-start;
 }
 .van-wraper .van-item:not(:first-child){
   margin-top: 40rpx;
 }
 .van-wraper .van-item .comm-left{
   margin-right: 22rpx;
 }
 .van-wraper .van-item .comm-left image{
   width: 174rpx;
   height: 226rpx;
 }
 .van-wraper{
   margin-top: 40rpx;
 }
 .van-wraper .van-item .comm-info{
   display:flex;
   justify-content: flex-start;
   flex-direction: column;
 }
 .van-wraper .van-item .comm-info .title{
 font-size: 28rpx;
 font-family: SourceHanSansCN-Bold;
 color: #333333;
 }

js:

data: {
    fatherList: [
      {
        tabsName: '标签一',
        list: [
          {
            imgUrl: '../../static/img/index-img.png',
            title: 'xxx公司'
          },
          {
            imgUrl: '../../static/img/index-img.png',
            title: 'xxx公司'
          },
          {
            imgUrl: '',
            title: 'xxx公司'
          }
        ]
      },
      {
        tabsName: '标签二',
        list: [
          {
            imgUrl: '../../static/img/index-img.png',
            title: 'xxx公司'
          },
          {
            imgUrl: '../../static/img/index-img.png',
            title: 'xxx公司'
          },
          {
            imgUrl: '',
            title: 'xxx公司'
          }
        ]
      },
      {
        tabsName: '标签三',
        list: [
          {
            imgUrl: '../../static/img/index-img.png',
            title: 'xxx公司'
          },
          {
            imgUrl: '../../static/img/index-img.png',
            title: 'xxx公司'
          },
          {
            imgUrl: '',
            title: 'xxx公司'
          }
        ]
      }
    ]
  },

注意当标签文字内容过长显示不全时,我们需要在标签上加上tab-class=“tab-box”,然后给tab-box给样式 flex: none !important;,当没加这个样式时,文字过长时会出现省略号,如下图所示:
在这里插入图片描述
当加上该类时的样式时显示如下:
在这里插入图片描述
整体页面效果如下:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值