1、踩坑排错
scroll-view
基础库 1.0.0 开始支持,低版本需做兼容处理。
可滚动视图区域。使用竖向滚动时,需要给scroll-view一个固定高度,通过 WXSS 设置 height。组件属性的长度单位默认为px,2.4.0起支持传入单位(rpx/px)。
属性 | 类型 | 默认值 | 必填 | 说明 | 最低版本 |
---|---|---|---|---|---|
scroll-x | boolean | false | 否 | 允许横向滚动 | 1.0.0 |
scroll-y | boolean | false | 否 | 允许纵向滚动 | 1.0.0 |
纵向滑动
-
效果图
-
支持浮动布局,盒型布局,定位布局等兼容效果较佳
-
效果图
注意必须在style中添加、scroll-y=“true” style=“height:800rpx;”、否则无法滚动
横向滚动
- 效果图
- 天坑–不支持盒型布局 display:flex 、下面的页面开发中有其他布局的css
2、页面开发
全部封装成模板了、可直接导入使用
布局一
- 效果图
-
代码
-
<template name="takeout"> <view class="store-box"> <view class="item-box" wx:for="{{ storeList }}" wx:key="key" bindtap="toStore" data-id="{{ item.shop.id }}"> <view class="container top-box"> <view class="left"> <image src="{{ item.shop.main_img_url }}"></image> </view> <view class="right"> <text class="tit" >{{item.shop.name}}</text> <text class="store-tag">外</text> <view class="row justify-content"> <view class="row-left"> <i class="hxicon-favorfill "></i> <text class="t1">★{{item.shop.hot/20.0}}</text> <text class="t2">月售{{item.shop.monthly_sales?'item.shop.monthly_sales':'0'}}</text> </view> <view class="row-right"> <i class="hxicon-locationfill"></i> <text style="color: #576B95;">{{item.shop.distance?item.shop.distance:'定位中'}}</text> </view> </view> <view class="row"> <text >起送¥{{item.shop.price}}</text> <text class="t2" wx:if="store.shipping_dees > 0">配送¥{{item.shop.shipping_dees?item.shop.shipping_dees:'0'}} </text> <text class="t2" wx:else>免费配送</text> <text >人均¥{{item.shop.price}}</text> </view> <!-- <view class="row"> </view> --> </view> </view> <scroll-view scroll-x="true" class="bottom-box"> <view class="bottom-box-container"> <view class="goods-box" wx:for="{{item.food}}" wx:key="key"> <view class="img-box"> <image src="{{ item.img_url }}"></image> <view class="tag"> {{item.tag?'item.tag':'招牌'}} </view> </view> <view class="tit"> {{item.name}} </view> <view class="price-box"> <text class="txt1">¥</text> <text class="txt2">{{item.price}}*{{item.counts}}</text> <text class="txt3">¥{{item.price_s}}</text> </view> </view> </view> </scroll-view> </view> </view> </template>
.store-box { margin: 0rpx 10rpx; } .store-box .item-box { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; flex-direction: column; background-color: #ffffff; margin-top: 10rpx; padding: 30rpx 20rpx; } .store-box .item-box .top-box { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; flex-direction: row; } .store-box .item-box .top-box .left { margin-right: 10px; } .store-box .item-box .top-box .left image { width: 72px; height: 54px; border-radius: 6px; } .store-box .item-box .top-box .right { -webkit-box-flex: 1; -webkit-flex: 1; flex: 1; position: relative; overflow: hidden; } .store-box .item-box .top-box .right .tit { font-size: 16px; font-weight: bold; color: #333333; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .store-box .item-box .top-box .right .justify-content { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; flex-direction: row; -webkit-box-pack: justify; -webkit-justify-content: space-between; justify-content: space-between; } .store-box .item-box .top-box .right .row { font-size: 12px; color: #999999; margin-top: 4px; } .store-box .item-box .top-box .right .row .row-left { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; flex-direction: row; } .store-box .item-box .top-box .right .row .row-left .t1, .store-box .item-box .top-box .right .row .row-left ._i { color: #ffca3e; } .store-box .item-box .top-box .right .row .t2 { margin: 0 12rpx; } .store-box .item-box .top-box .right .row .row-right { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; flex-direction: row; } .store-box .item-box .top-box .right .row .row-right ._i { margin-right: 4px; } .store-box .item-box .bottom-box-container { /* margin: 12px 0 0; */ margin-top: 10rpx; padding-left: 140rpx; white-space: nowrap; } .store-box .item-box .bottom-box-container .goods-box { width: 80px; margin-left: 12px; display: inline-block; } .store-box .item-box .bottom-box-container .goods-box .img-box { position: relative; width: 80px; height: 60px; background-color: #f1f1f1; border-radius: 4px; } .store-box .item-box .bottom-box-container .goods-box .img-box image { width: 100%; height: 60px; } .store-box .item-box .bottom-box-container .goods-box .img-box .tag { position: absolute; bottom: 0; left: 0; background-color: #FF5722; color: #ffffff; padding: 2px 4px; font-size: 12px; border-radius: 4px; } .store-box .item-box .bottom-box-container .goods-box .tit { font-size: 14px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .store-box .item-box .bottom-box-container .goods-box .price-box { margin-top: 4px; } .store-box .item-box .bottom-box-container .goods-box .price-box .txt1 { font-size: 10px; color: #FF5722; } .store-box .item-box .bottom-box-container .goods-box .price-box .txt2 { font-size: 16px; color: #FF5722; } .store-box .item-box .bottom-box-container .goods-box .price-box .txt3 { margin-left: 6px; font-size: 10px; color: #bbbbbb; text-decoration: line-through; } .store-box .item-box .bottom-box-container .goods-box:last-child { margin-right: 12px; } .store-box .item-box:last-child { border-bottom: 0; } .store-tag{ position: absolute; right: 0; width: 30rpx; height: 30rpx; text-align: center; background-color: rgb(255, 244, 226); color: #ffca3e; font-weight: bold; top: 0; }
-
布局二
- 效果图
-
代码
-
<template name="shop"> <view class="shop-box" wx:for="{{shopArr}}" wx:key="id" bindtap="toShopDetail" data-id="{{ item.id }}"> <view class="shop-avatar"> <image class="shop-img" src="{{ item.main_img_url ? item.main_img_url : '../../images/icon/blank.png' }}" mode="aspectFill"></image> </view> <view class="shop-info"> <text class="shop-title">{{item.name}}</text> <view class="shop-content"> <view class='stars-container'> <view class='stars'> <block wx:for="{{ (item.hot/20) }}" wx:for-item="i" wx:key="position"> <image wx:if="{{i+1}}" src='/images/icon/star@selected.png'></image> <!-- <image wx:elif="{{i==2}}" src='/images/icon/star@before.png'></image> --> <image wx:else src='/images/icon/star@before.png'></image> </block> </view> <text class='star-score'>{{ (item.hot/20.0) }}分</text> </view> <text class="shop-price">¥{{item.price}}/人</text> <text>2.5km</text> </view> <view class="shop-category"> <text>传统中餐/堂食</text> <text>季度单数520</text> </view> <view class="shop-active"> <text>惠</text> <text>25.8元金典单人套餐,50元惬意双人套餐</text> </view> <!-- 活动logo --> <view class="n-s-c-status"> <block wx:for="{{ item.coupon }}" wx:key="id"> <text class="n-s-c-s-left">满{{item.isprice}}送券{{item.lose_price}}</text> </block> </view> </view> <!-- 类别标志 --> <view class="shop-star"> <text class="shop-tag">外</text> </view> </view> </template>
/*首页商家*/ .shop-box{ display: flex; flex-direction: row; align-items: center; margin: 0rpx 10rpx 10rpx 10rpx; padding: 20rpx; position: relative; background-color:#fff; height: 250rpx; border-radius: 8rpx; } .shop-img{ width:220rpx; height:240rpx; border-radius: 10rpx; margin-right: 20rpx; } .shop-info{ width:520rpx; display:flex; flex-direction: column; color:#666; line-height: 1.5; text-align: justify; height: 250rpx; } .shop-title{ font-size: 32rpx; color:#333; font-weight: 900; } .shop-price{ color: red; font-size: 24rpx; font-weight: bold; } .shop-content{ display: flex; overflow: hidden; flex-wrap: nowrap; margin: 10rpx 0; align-items: center; position: relative; } .stars-container { display: flex; flex-direction: row; } .stars { display: flex; flex-direction: row; align-items: center; } .stars image { padding-left: 3rpx; height: 24rpx; width: 24rpx; } .star-score { margin: 0 10rpx; } .shop-content>text:first-child{ color: #ff7440; } .shop-content>text:last-child{ position: absolute; right: 0; margin-right: 5rpx; } .shop-category{ display: flex; overflow: hidden; position: relative; } .shop-category>text:last-child{ position: absolute; right: 0; margin-right: 5rpx; color: #ff7440; font-weight: bold; } .shop-active{ display: flex; text-overflow: ellipsis; overflow: hidden; text-align: center; margin: 10rpx 0; flex-wrap: nowrap; } .shop-active text:first-child{ background-color: #ff7440; color: #fff; margin-right: 10rpx; text-align: center; width: 30rpx; } .shop-active text:last-child{ text-overflow: ellipsis; white-space: nowrap; margin-right: 10rpx; } .n-s-c-status { display: flex; overflow: hidden; flex-wrap: nowrap; } .n-s-c-status .n-s-c-s-left { color: #ff7440; padding: 2rpx 4rpx; border-radius: 8rpx; border: #ff7440 1rpx solid; margin-right: 10rpx; white-space: nowrap; font-size: 22rpx; font-weight: bold; } .n-s-c-status .n-s-c-s-left-gray { color: #ccc; padding: 2rpx 4rpx; border-radius: 5rpx; border: solid 1rpx #ccc; margin-right: 15rpx; white-space: nowrap; } .shop-star{ position: absolute; right:10rpx; top:10rpx; display: flex; flex-direction: column; align-items: center; background-color: rgb(255, 244, 226); padding: 5rpx; } .shop-tag{ text-align: center; color: #ff7440; font-weight: bold; }
-
布局三
- 效果图
-
代码
-
<template name="shop-update"> <view class="stores" wx:for="{{ shopArr }}" wx:key="id" bindtap="toShopDetail" data-id="{{ item.store_id }}"> <view class="single-store"> <!-- head --> <view class="store-head"> <image src="{{ item.avatar ? item.avatar : '../../images/icon/blank.png' }}" mode="aspectFill"></image> <view class="store-content"> <text>{{item.name}} ( {{item.community}} )</text> <view class="store-content-text"> <text>★{{ item.mark }}</text> <text>{{ item.distance }}m</text> </view> </view> <text>进店 ></text> </view> <!-- logo --> <view class="store-log"> <view class="log-box"> <text>满额送券</text> </view> <view class="log-box"> <text>自推活动</text> </view> <view class="log-box"> <text>用餐有奖</text> </view> <view class="log-box"> <text>支持外卖</text> </view> </view> <!-- pic --> <view class="store-botton"> <scroll-view scroll-x="true" style="width:100%"> <view class="store-dishes-boxs"> <view class="store-dishes" wx:for="{{item.goods}}" wx:key="id"> <image src="{{item.main_pic}}"></image> <view class="store-dishes-name">{{item.name}}</view> <view class="store-dishes-price"> <text>{{item.price}}</text> <text>原{{item.old_price}}</text> </view> </view> </view> </scroll-view> </view> </view> </view> </template>
/* -------------update tmplate css---------------- */ .stores{ display: flex; flex-direction: column; overflow: hidden; margin: 0 10rpx; } .single-store{ overflow: hidden; background-color: #fff; margin-bottom: 10rpx; border-radius: 10rpx; display: flex; flex-direction: column; padding: 10rpx; } .store-head image{ width: 105rpx; height: 100rpx; border-radius: 10rpx; } .store-head{ display: flex; margin: 10rpx; align-items: flex-start; position: relative; } .store-head>text{ font-size: 30rpx; font-weight: 600; color: #000; /* margin-left: 300rpx; */ position: absolute; right: 0; } .store-content{ display: flex; flex-direction: column; margin-left: 20rpx; } .store-content>text:first-child{ font-size: 30rpx; font-weight: 600; color: #000; } .store-content-text{ display: flex; } .store-content-text>text:first-child{ margin-right: 10rpx; color: rgb(255, 160, 0); } .store-log{ display: flex; overflow: hidden; } .log-box{ margin: 0 10rpx; height: 30rpx; background-color: rgb(254, 244, 242); padding: 6rpx; line-height: 30rpx; border-radius: 5rpx; } .log-box>text{ color: rgb(242, 83, 18); font-weight: 600; } .store-botton{ margin-top: 20rpx; display: flex; flex-direction: row; } .store-dishes-boxs{ display: block; overflow: scroll; white-space: nowrap; } .store-dishes{ display:inline-block; margin: 0 0 10rpx 15rpx; } .store-dishes>image{ width: 150rpx; height: 120rpx; border-radius: 15rpx; } .store-dishes-name{ color: #000; width: 150rpx; margin-top: 5rpx; font-size: 26rpx; flex-wrap: nowrap; height: 40rpx; overflow: hidden; text-overflow: ellipsis; } .store-dishes-price{ display: flex; align-items: flex-end; } .store-dishes-price text:first-child{ color: rgb(242, 83, 18); font-size: 32rpx; font-weight: 600; margin-right: 10rpx; } .store-dishes-price text:last-child{ text-decoration: line-through; color: #aaa; }
-