点击不同的按钮(标签)进行内容的切换

本文介绍了用户可以通过点击按钮在最新资讯、点赞最多的帖子和个人爆料之间切换的功能。界面设计简洁,便于用户根据需求筛选内容。
<view class="page">
    <view class="btn">
      <view
        @click="show(1)"
        :style="{
          width: '150rpx',
		  marginRight: '10px',
        }"
        :class="index === 1 ? 'active' : 'active1'"
        >最新</view
      >
      <view
        @click="show(2)"
        :style="{
          width: '150rpx',
		  marginRight: '10px',
        }"
        :class="index === 2 ? 'active' : 'active1'"
        >最多点赞</view
      >
      <view
        @click="show(3)"
        :style="{
          width: '150rpx',
		  marginRight: '10px',
        }"
        :class="index === 3 ? 'active' : 'active1'"
        >我的爆料</view
      >
    </view>
    <!-- 所有资讯 -->
    <view v-show="index === 1 && isShow">1</view>

    <!-- 考级-->
    <view v-show="index === 2 && isShow">2</view>

    <!-- 考试 -->
    <view v-show="index === 3 && isShow">3</view>
  </view>
data() {
    return {
      // 控制切换按钮后按钮改变样式
      index: 1,
      // 控制点击按钮后子组件显示,再次点击隐藏
      isShow: true,
    }
   }
methods: {
    show(value) {
      this.index === value
        ? (this.isShow = this.isShow)
        : (this.isShow = true);
      this.index = value;
    },
}
.page {
  .btn {
    display: flex;
    flex-direction: row;
    .active {
      width: 80px;
      height: 26px;
      line-height: 26px;
	  
      border-radius: 30px;
      background-color: rgba(90, 192, 207, 100);
      color: rgba(255, 255, 255, 100);
      font-size: 14px;
      text-align: center;
    }
    .active1 {
      width: 80px;
      height: 26px;
      line-height: 26px;
      border-radius: 30px;
      background-color: rgba(245, 245, 250, 100);
      color: rgba(111, 111, 111, 100);
      font-size: 14px;
      text-align: center;
    }
  }
}

效果图

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值