react 动态切换轮播图卡片

在这里插入图片描述

通过换一组切换卡片,也可以滑动卡片切换,效果如图⬆️

import { Carousel, Card } from 'antd-mobile';
import { inject, observer } from 'mobx-react';
interface Props {
  configStore: ConfigStore;
}
@inject('configStore')
@observer
export default class HomePage extends React.Component{
	render() {
	  //卡皮信息
	   const bannerList = [{  }];
	   const { configStore } = this.props;
	   const { selectedIndex } = configStore;
	   <div className={`${prefixCls}-recommend-header`}>
		<span
		className={`${prefixCls}-recommend-header-btn`}
		onClick={() => this.switchHandle()}>
		换一组
		<img
		src={refresh}
		className={`${prefixCls}-recommend-header-btn-refresh`}
		/>
		</span>
		<div className={`${prefixCls}-recommend-body`}>
			<Carousel	
			selectedIndex={selectedIndex}
			className={`${prefixCls}-recommend-body-carousel space-carousel`}
			frameOverflow="visible"
			cellSpacing={10}
			infinite
			dotStyle={{
			  background: '#D6D6D6',
			  borderRadius: '1.5px',
			  width: '20.4px',
			  height: '3px',
			}}
			dotActiveStyle={{
			  background: '#003FB9',
			  borderRadius: '1.5px',
			  width: '20.4px',
			  height: '3px',
			}}>
			{bannerList.map((item, index) => (
			  <Card
			    key={String(index)}
			    className={`${prefixCls}-recommend-body-card`}>
			  </Card>
			))}
			</Carousel>
		</div>
	   </div>
	}
	switchHandle() {
	   const { configStore } = this.props;
	   const { selectedIndex } = configStore;
	   if (selectedIndex === 2) {
	     configStore.setSelectedIndex(0);
	   } else {
	     configStore.setSelectedIndex(selectedIndex + 1);
	   }
	 }
}

CSS部分

&-recommend {
    margin: arem(4.16) 0 arem(4.96);
    padding: 0 arem(3.04) 0 arem(3.2);

    &-header {
      display: flex;
      justify-content: space-between;
      margin-bottom: arem(3.84);
      
      &-btn {
        font-size: 12px;
        color: #2557e6;
        line-height: 18px;

        &-refresh {
          width: arem(2.24);
          margin-top: arem(0.2);
          margin-left: arem(1.12);
          vertical-align: top;
          line-height: 18px;
        }
      }
    }

    &-body {
      margin: arem(3.84) 0 arem(4.96);
      width: 100%;
      min-height: arem(41.7);
      overflow: hidden;

      .slider-decorator-0 {
        bottom: -20px !important;
      }

      &-card {
        background-color: #F8F8F8;
        border-radius: 10px !important;
        padding: arem(2.08) arem(3.04);
        box-shadow: 0 10px 40px -12px rgba(0, 0, 0, 0.35),
          inset 0 1px 1px 0 #ffffff;
      }
    }
  }

configStore.ts

import { observable } from 'mobx';
export default class HomeStore {
  @observable selectedIndex = 0; 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值