uniapp实现顶部tab选项卡

摘自https://www.cnblogs.com/xhxdd/p/11941133.html

uniapp实现顶部tab选项卡

 

HTML

复制代码
<view class="end-title">
  <view @tap="change(0)" :class="{btna:btnnum == 0}">基本信息</view>
   <view @tap="change(1)" :class="{btna:btnnum == 1}">公告信息</view>
  <view @tap="change(2)" :class="{btna:btnnum == 2}">换区信息</view>
</view>
<view class="end-cont" :class="{dis:btnnum == 0}">
   0信息
</view>
<view class="end-cont" :class="{dis:btnnum == 1}">
   1信息
</view>
<view class="end-cont" :class="{dis:btnnum == 2}">
   2信息
</view>
复制代码

CSS

复制代码
    /* 将三个内容view的display设置为none(隐藏) */
    .end-title{
        display: flex;
    }
    .end-title view{
        flex-grow: 1;
        text-align: center;
    }
    .end-cont{
        display: none;
        background: #C8C7CC;
    }
    .btna{
        color: #FFFFFF;
        background: #00A0FF;
    }
    .dis{
        display: block;
    }    
复制代码

JS

复制代码
data() {
   return {
      btnnum: 0,
   };
},
methods:{
   change(e) {
      this.btnnum = e
      console.log(this.btnnum)
  }
}
复制代码

 HTML循环实现tab选项卡

html

复制代码
<view class="end-title">
     <view v-for="(item,index) in items" :key="index" :class="{btna:count == index}" @tap="change(index)">
        {{item}}
    </view>
</view>
<view class="end-cont" :class="{dis:btnnum == 0}">
  0信息
</view>
<view class="end-cont" :class="{dis:btnnum == 1}">
  1信息
</view>
<view class="end-cont" :class="{dis:btnnum == 2}">
  2信息
</view>
复制代码

CSS同上

js

复制代码
data() {
   return {
      btnnum: 0,
      items:["基本信息","公告信息","换区信息"],
      count:"",
  };
},
methods:{
  change(e) {
     this.count = e
     this.btnnum = e
     console.log(this.count)
  }
}
复制代码

 

样式展示:

 

 

 

 

posted @ 2021-09-13 18:23  wu9xia  阅读(929)  评论(0编辑  收藏  举报