uniapp(2)——切换卡片

uniapp原始语法

    <!-- 默认页面 -->
    <view class="main" v-if="active==0">
            
    </view>

    <!-- 页面1 -->
    <view class="main" v-if="active==1">
      
    </view>

    <!-- 页面2 -->
    <view class="main" v-if="active==2">
      
    </view>
methods: {
      selectIndex(item) {
        this.active = item
        if (item == 0) {

            ...
          
        } else if (item == 1) {

            ...

        }else if (item == 2) {
          
            ...
        }
      },
}
data() {
      return {
        active: 0,
        
      }
    },

uview-ui语法

<template>
  <view class="content">
    <Header></Header>
    <view class="home-tabs">
      <u-tabs :list="topBar" @change="changeTabs" :current='current' :inactiveStyle="{
            color: '#AAAAAA',
            transform: 'scale(1)'
        }" :activeStyle="{
            color: '#333333',
            fontWeight: 'bold',
            fontSize:'29rpx'
        }">
      </u-tabs>
    </view>
    <view class="home-swiper">
      <swiper :duration="500" :current="current" @change="changeSwiper">
        <swiper-item v-for="(item,index) in topBar" :key="index">
          <component :is='activeCom'></component>
        </swiper-item>
      </swiper>
    </view>
    
  </view>
</template>

 activeCom: Recommend,
        current: 0,
        topBar: [{
          name: '今日推荐',
        }, {
          name: '美食'
        }, {
          name: '文化'
        }]
methods: {
      // 切换tabs
      changeTabs({index}) {
        this.current = index
        this.tabsCom(index)
      },
      // 切换swiper
      changeSwiper(e) {
        this.current = e.detail.current
        this.tabsCom(e.detail.current)
      },
      // 判断动态组件显示
      tabsCom(index) {
        switch (index) {
          case 0:
            this.activeCom = Recommend
            break;
          case 1:
            this.activeCom = Food
            break;
          case 2:
            this.activeCom = Culture
            break;        
        }
      },
    }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值