display: flex多栏多列布局(实例)

我们先来看看效果

其实很简单,来看看代码具体怎么实现的吧

wxml

<!--pages/new/new-exclusive/index.wxml-->
<view class="new-exclusive">
  <!-- 轮播图 S -->
  <swiper class="viewpager" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" circular="{{circular}}" bindchange="changeSwiper">
    <swiper-item wx:for="{{slideshow}}" wx:key="index">
      <image src="{{item.showImg}}" class="image"></image>
    </swiper-item>
  </swiper>
  <!-- <view class="dots">
    <block wx:for="{{slideshow}}" wx:key="index">
      <view class="dot{{index == currentSwiper ? ' active-z' : ''}}"></view>
    </block>
  </view> -->
  <!-- 轮播图 E -->
  <view class="new-exclusive-desc">
    <view>新人专享超值低价</view>
    <view>活动规则:每个ID限购一件,申请退款的不再享受该优惠</view>
  </view>

  <!-- 写入内容 S -->
  <view class="goods-list">
    <block wx:for="{{list}}" wx:key="index">
      <view class="goods">
        <image class="cover-img" src="../../../img/shangpin.jpg"></image>
        <view class="goods-title">{{item.title}}</view>
        <view class="goods-price">
          <text>¥</text>
          <text>{{item.price}}</text>
          <text>.</text>
          <text>00</text>
          <text>¥</text>
          <text>{{item.original_price}}</text>
        </view>
      </view>
    </block>
  </view>
  <!-- 写入内容 E -->
</view>

主要看写入内容这块,其他的都是辅助效果

wxss

.new-exclusive {
  background-image: url('http://ico.dongtiyan.com/tu-9.png');
  padding-bottom: 30rpx;
}
/* 轮播图 */
.viewpager {
  height: 162rpx;
  border-radius: .5rem;
  margin-bottom: 12rpx;
  overflow: hidden;
  margin: 0 30rpx 41rpx;
  padding-top: 23rpx;
}
.viewpager .image {
  width: 100%;
  height: 100%;
  border-radius: .5rem;
}

/*用来包裹所有的小圆点 */
.dots {
  margin-bottom: 20rpx;
  display: flex;
  flex-direction: row;
  justify-content: center;
}

/*未选中时的小圆点样式 */

.dot {
  width: 7rpx;
  height: 6rpx;
  border-radius: 3rpx;
  margin-right: 26rpx;
  background-color: #BFBFBF;
}

/*选中以后的小圆点样式 */

.active-z {
  width: 26rpx;
  height: 6rpx;
  border-radius: 3rpx;
  background-color: #EC5E64;
}

.new-exclusive-desc {
  text-align: center;
  color: #FFFFFF
}
.new-exclusive-desc view:nth-child(1) {
  font-size: 32rpx;
  font-weight: bold;
}

.new-exclusive-desc view:nth-child(2) {
  font-size: 20rpx;
  margin-top: 15rpx;
}

/* 商品列表 */

.goods-list {
  display: -webkit-flex;
  background: #FEDCDC;
  border-radius: 20rpx;
  margin: 32rpx 20rpx;
  overflow: hidden;
  padding: 29rpx 20rpx 0;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  text-align: justify;
}
.goods-list::after {
  content: '';
  width: 218rpx;
}
.goods {
  width: 218rpx;
  background: #FFFFFF;
  border-radius: 10rpx;
  overflow: hidden;
  margin-bottom: 28rpx;
}
.cover-img {
  width: 100%;
  height: 164rpx;
}

.goods-title {
  margin-top: 18rpx;
  font-size: 20rpx;
  padding: 0 9rpx;
  color: #000000;
  text-overflow: -o-ellipsis-lastline;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.goods-price {
  color: #F73A3F;
  padding: 0 9rpx 11rpx;
}

.goods-price text:nth-child(1), .goods-price text:nth-child(3), .goods-price text:nth-child(4) {
  font-size: 16rpx;
}
.goods-price text:nth-child(2) {
  font-size: 24rpx;
}

.goods-price text:nth-child(5) {
  margin-left: 10rpx;
}
.goods-price text:nth-child(5), .goods-price text:nth-child(6) {
  font-size: 12rpx;
  color: #999999;
}
.goods-price text:nth-child(6) {
  text-decoration: line-through;
}

js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    slideshow: [{
        id: 1,
        showImg: "../../../img/slideshow/vivo.jpg"
      },
      {
        id: 2,
        showImg: "../../../img/slideshow/xinchun.jpg"
      }
    ],
    // 轮播数据 + 效果 S
    indicatorDots: true,
    autoplay: true, // 自动播放
    interval: 5000, //轮播时间
    duration: 300, // 滑动速度越大越慢
    circular: true, //是否循环
    beforeColor: "lightgray", //指示点颜色
    afterColor: "white", //当前选中的指示点颜色
    currentSwiper: 0,
    list: [
      {
        title: "商品标题显示两行商品标题显示两行商品标题显示两行商品标题显示两行",
        price: "520",
        original_price: "1314.00", 
      },
      {
        title: "商品标题显示两行商品标题显示两行商品标题显示两行商品标题显示两行",
        price: "520",
        original_price: "1314.00",
      },
      {
        title: "商品标题显示两行商品标题显示两行商品标题显示两行商品标题显示两行",
        price: "520",
        original_price: "1314.00",
      },
      {
        title: "商品标题显示两行商品标题显示两行商品标题显示两行商品标题显示两行",
        price: "520",
        original_price: "1314.00",
      },
      {
        title: "商品标题显示两行商品标题显示两行商品标题显示两行商品标题显示两行",
        price: "520",
        original_price: "1314.00",
      },
      {
        title: "商品标题显示两行商品标题显示两行商品标题显示两行商品标题显示两行",
        price: "520",
        original_price: "1314.00",
      },
      {
        title: "商品标题显示两行商品标题显示两行商品标题显示两行商品标题显示两行",
        price: "520",
        original_price: "1314.00",
      },
      {
        title: "商品标题显示两行商品标题显示两行商品标题显示两行商品标题显示两行",
        price: "520",
        original_price: "1314.00",
      },
      
    ]
  },
  /**
   * 轮播指示灯
   */
  changeSwiper: function (e) {
    this.setData({
      currentSwiper: e.detail.current
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})

以上就是所有代码,很简单,有什么不懂的可以加下群

QQ群: 1102727334

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值