zoukankan      html  css  js  c++  java
  • taro 自定义 轮播图组件

    1.代码

    components/MySwiper/index.js

    /**
     * 轮播图组件
     */
    import Taro, { Component } from '@tarojs/taro';
    import { Swiper, SwiperItem, Image } from '@tarojs/components';
    import PropTypes from 'prop-types';
    import './index.scss';
    
    export default class MySwiper extends Component {
      static propTypes = {
        banner: PropTypes.array,
      };
    
      static defaultProps = {
        banner: [],
      };
    
      render() {
        const { banner } = this.props;
        return (
          <Swiper
            className="swiper-container"
            circular
            indicatorDots
            indicatorColor='#999'
            indicatorActiveColor='#bf708f'
            autoplay>
            { banner.map((item, index) => (
              <SwiperItem key={index}>
                <Image className="swiper-img" mode="widthFix" src={item.image_src}></Image>
              </SwiperItem>
            ))}
          </Swiper>
        )
      }
    }
    

    components/MySwiper/index.less

    @import "../../styles/mixin";
    
    .swiper-container {
       100vw;
      height: 450px;
      .swiper-img,img {
        height: 450px!important;
      }
    }
    

    2.调用

    render() {
      const { banner } = this.props;
      return (
        <View className="home-page">
          <MySwiper banner={banner} />
        </View>
      )
    }

    3.效果图

  • 相关阅读:
    Web全栈探索,Vue基础系列,前后端交互(四)
    幸运者
    整数加法
    猜数游戏
    multi-select 左右选择插件
    Layui 踩坑记录
    jQuery 封装公共方法
    前后端文件内容 md5 计算
    Apscheduler 定时任务
    Git 开发流程
  • 原文地址:https://www.cnblogs.com/crazycode2/p/9937534.html
Copyright © 2011-2022 走看看