仿美团外卖商品列表
简易实现美团外卖商品列表,没什么技术难点,简单来说就是两个scroll-view
协作,并且两个scroll-view
不会滑动冲突。
实际效果
仿美团外卖商品列表实际项目效果
简介
左右两个scroll-view
简易实现美团外卖商品列表功能。rightBar
属性仅为示例,可根据实际数据结构二次开发。
属性介绍
属性名 | 类型 | 默认值 | 必填 | 说明 |
---|
shopOptions | Object | | 是 | 商品列表整体数据。 |
shopList | Array | | 是 | shopOptions 下属性,不能单独使用。 |
leftBar | Object | | 是 | shopOptions 下属性,不能单独使用。 |
rightBar | Object | | 是 | shopOptions 下属性,不能单独使用。 |
1、shopList
属性名 | 类型 | 默认值 | 必填 | 说明 |
---|
shopList | Array | 空 | 是 | 商品列表数据。本文仅为示例,数据结构不同,可根据数据结构二次开发本插件。 |
2、leftBar
属性名 | 类型 | 默认值 | 必填 | 说明 |
---|
leftBarWidth | String | 空 | 是 | 左部导航栏长度,例:25%、100px |
leftBarBgColor | String | 空 | 是 | 左部导航栏背景色,例:red、#fff |
leftBarItemHeight | String | 空 | 是 | 左部导航栏Item 宽度,例:25px |
leftBarItemFontSize | String | 空 | 是 | 左部导航栏Item 字体大小,例:12px |
leftBarItemSelectFontSize | String | 空 | 是 | 左部导航栏Item 选择时字体大小,例:12px |
leftBarItemFontWeight | String | 空 | 是 | 左部导航栏Item 字体粗细,例:400 |
leftBarItemSelectFontWeight | String | 空 | 是 | 左部导航栏Item 选择时字体粗细,例:400 |
leftBarItemFontColor | String | 空 | 是 | 左部导航栏Item 字体颜色,例:red 、#fff |
leftBarItemSelectFontColor | String | 空 | 是 | 左部导航栏Item 选择时字体颜色,例:red 、#fff |
leftBarItemBgColor | String | 空 | 是 | 左部导航栏Item 背景颜色,例:red 、#fff |
leftBarItemSelectBgColor | String | 空 | 是 | 左部导航栏Item 选择时背景颜色,例:red 、#fff |
3、rightBar
属性名 | 类型 | 默认值 | 必填 | 说明 |
---|
rightBarWidth | String | 空 | 是 | 右部导航栏长度,例:75%、650px |
rightBarBgColor | String | 空 | 是 | 右部导航栏背景色,例:red、#fff |
rightBarItemImgWidth | String | 空 | 是 | 右部商品列表Item 图片长宽,例:40px |
rightBarItemTitleFontSize | String | 空 | 是 | 右部商品列表Item 标题字体大小,例:12px |
rightBarItemTitleFontWeight | String | 空 | 是 | 右部商品列表Item 标题字体粗细,例:500 |
rightBarItemTitleFontColor | String | 空 | 是 | 右部商品列表Item 标题字体颜色,例:red 、#fff |
rightBarItemDesFontSize | String | 空 | 是 | 右部商品列表Item 描述信息字体大小,例:12px |
rightBarItemDesFontWeight | String | 空 | 是 | 右部商品列表Item 描述信息字体粗细,例:500 |
rightBarItemDesFontColor | String | 空 | 是 | 右部商品列表Item 描述信息字体颜色,例:red 、#fff |
rightBarItemPriceFontSize | String | 空 | 是 | 右部商品列表Item 价格字体大小,例:12px |
rightBarItemPriceFontWeight | String | 空 | 是 | 右部商品列表Item 价格字体粗细,例:500 |
rightBarItemPriceFontColor | String | 空 | 是 | 右部商品列表Item 价格字体颜色,例:red 、#fff |
事件介绍
事件名 | 说明 |
---|
@rightBarItemClick | 右部商品列表item点击事件。返回值event:{superIndex: 2, index: 0} ,superIndex :左部导航栏当前选择的下标,index :右部商品列表当前点击的下标。 |
使用示例
<view class="container">
<bugking7-shop-view
:shopOptions="shopOptions"
@rightBarItemClick="handleRightClick"></bugking7-shop-view>
</view>
import tabbarItem from '@/pages/index/data.js'
data() {
return {
shopOptions: {
shopList: tabbarItem.tabbarItem,
leftBar:{
leftBarWidth:'25%',
leftBarBgColor:'',
leftBarItemHeight:'40px',
leftBarItemFontSize:'13px',
leftBarItemSelectFontSize:'14px',
leftBarItemFontWeight:'400',
leftBarItemSelectFontWeight:'500',
leftBarItemFontColor:'black',
leftBarItemSelectFontColor:'#fff',
leftBarItemBgColor:'#f5f5f5',
leftBarItemSelectBgColor:'#2979ff'
},
rightBar:{
rightBarWidth:'75%',
rightBarBgColor:'white',
rightBarItemImgWidth:'40px',
rightBarItemTitleFontSize:'15px',
rightBarItemTitleFontWeight:'500',
rightBarItemTitleFontColor:'black',
rightBarItemDesFontSize:'13px',
rightBarItemDesFontWeight:'300',
rightBarItemDesFontColor:'gray',
rightBarItemPriceFontSize:'15px',
rightBarItemPriceFontWeight:'600',
rightBarItemPriceFontColor:'red',
}
}
}
},
methods: {
handleRightClick(e){
console.log(e)
}
}
数据结构示例(shopList)
本组件仅为示例,商品列表数据只为测试使用。如果要在项目中使用本组件,请根据数据结构二次开发。注:shopList数据结构须与二次开发组件中右部商品列表v-for时一致。
export default {
"tabbarItem": [
{
"name": "京东",
"id": "jd",
"list": [
{
"title": "京东plus年卡",
"subTitle": "限时优惠",
"desc": "详情请点击>>>",
"price": "¥99",
"avatar": "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-7c798a00-b51f-42a8-bcad-d38005229108/621c6953-882d-4bbc-9afa-9adcfcc99c9f.jpeg",
"link": "https://hulumengke.suyur.com/detail?tid=500507660&mid=600309072&categoryId=262&groupId=296&productId=8980413150410",
"type": "link",
"imgPath": ""
},
{
"title": "1号店年卡",
"subTitle": "领取12个月鸡蛋",
"desc": "详情请点击>>>",
"price": "¥188",
"avatar": "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-7c798a00-b51f-42a8-bcad-d38005229108/57ce3357-2c6d-4c13-bd4f-ab851a6de4bd.jpeg",
"link": "https://hulumengke.suyur.com/detail?tid=500507660&mid=600309072&categoryId=262&groupId=296&productId=2380704173252",
"type": "link",
"imgPath": ""
}
]
},
{
"name": "腾讯视频",
"id": "txsp",
"list": [
{
"title": "月卡",
"subTitle": "限时优惠",
"desc": "详情请点击>>>",
"price": "¥18",
"avatar": "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-7c798a00-b51f-42a8-bcad-d38005229108/4bc77267-4982-44c3-8af9-19b2543329f2.jpeg",
"link": "https://hulumengke.suyur.com/detail?tid=500507660&mid=600309072&categoryId=157&groupId=106&productId=200309073",
"type": "link",
"imgPath": ""
},
{
"title": "季卡",
"subTitle": "限时优惠",
"desc": "详情请点击>>>",
"price": "¥50",
"avatar": "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-7c798a00-b51f-42a8-bcad-d38005229108/4bc77267-4982-44c3-8af9-19b2543329f2.jpeg",
"link": "https://hulumengke.suyur.com/detail?tid=500507660&mid=600309072&categoryId=157&groupId=106&productId=200309074",
"type": "link",
"imgPath": ""
}
]
}
]
}
存在问题
1、右部商品列表滑动时,左部导航栏暂未实现实时定位
uniapp
中scroll-view
的滑动事件监听,暂未实现根据计算滑动距离改变左部导航栏实时定位。如果有好的实现方式,欢迎评论留言。
插件地址
仿美团外卖商品列表