本文主要是介绍vue外卖二十二:商家详情-商家列表,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、有异步获取数据时 滑动创建时机page/shop/info/info.vue
1)有异步数据时要监视数据变动之后再刷新
<script>import {mapState} from 'vuex'import BScrool from '@better-Scroll/core' //滑动库export default{mounted(){// 【2】如果数据还没有pics, 直接结束if(!this.info.pics) {return}// 创建滚动实例this._initScroll()},computed:{...mapState(['info'])},watch:{// 【3】监视info数据如果更新了则再创建一次滚动实例info(){this.$nextTick(()=>{this._initScroll()})}},methods:{//【1】创建2个Bscroll滚动实例_initScroll(){//整体页面的纵向滚动new BScrool('.shop-info')// 动态计算ul的宽度const ul = this.$refs.picsUlconst liWidth = 120const space = 6const count = this.info.pics.length/*把计算出的宽度加到ul样式里:这么做原因是better-scroll宽度必须大于父元素.pic-wrapper才能实现横向滚动*/ul.style.width = (liWidth + space) * count -space + 'px'// 商家图片展示滚动实例new BScrool('.pic-wrapper',{scrollX:true})}}}
</script>
附件:完整代码
<template><div class="shop-info"><div class="info-content"><section class="section"><h3 class="section-title">配送信息</h3><div class="delivery"><div><span class="delivery-icon">{{info.description}}</span><span>由商家配送提供配送,约 {{info.deliveryTime}} 分钟送达,距离 {{info.distance}}</span></div><div class="delivery-money">配送费¥{{info.deliveryPrice}}</div></div></section><div class="split"></div><section class="section"><h3 class="section-title">活动与服务</h3><div class="activity"><!-- 【活动标签样式2】:根据数据的type显示对应的样式 --><div class="activity-item"v-for="(support,index) in info.supports":class="activeStyle[support.type]"><span class="content-tag"><span class="mini-tag">{{support.name}}</span></span><span class="activity-content">{{support.content}}</span></div></div></section><div class="split"></div><section class="section"><h3 class="section-title">商家实景</h3><div class="pic-wrapper"><ul class="pic-list" ref="picsUl"><li class="pic-item" v-for="(pic,index) in info.pics"><img width="120" height="90":src="pic"/></li></ul></div></section><div class="split"></div><section class="section"><h3 class="section-title">商家信息</h3><ul class="detail"><li><span class="bold">品类</span> <span>{{info.category}}</span></li><li><span class="bold">商家电话</span> <span>{{info.phone}}</span></li><li><span class="bold">地址</span> <span>{{info.address}}</span></li><li><span class="bold">营业时间</span> <span>{{info.workTime}}</span></li></ul></section></div></div>
</template><script>import {mapState} from 'vuex'import BScrool from '@better-Scroll/core'export default{data(){return{//【活动标签样式1】activeStyle:['activity-green','activity-red','activity-orange']}},mounted(){// 【2】如果数据还没有pics, 直接结束if(!this.info.pics) {return}// 创建滚动实例this._initScroll()},computed:{...mapState(['info'])},watch:{// 【3】监视info数据如果更新了则再创建一次滚动实例info(){this.$nextTick(()=>{this._initScroll()})}},methods:{//【1】创建2个Bscroll滚动实例_initScroll(){//整体页面的纵向滚动new BScrool('.shop-info')// 动态计算ul的宽度const ul = this.$refs.picsUlconst liWidth = 120const space = 6const count = this.info.pics.length/*把计算出的宽度加到ul样式里:这么做原因是better-scroll宽度必须大于父元素.pic-wrapper才能实现横向滚动*/ul.style.width = (liWidth + space) * count -space + 'px'// 商家图片展示滚动实例new BScrool('.pic-wrapper',{scrollX:true})}}}
</script><style lang="stylus" rel="stylesheet/stylus">@import "../../../common/stylus/mixins.styl".shop-infoposition: absolutetop: 195pxbottom: 0left: 0width: 100%background: #fff;overflow: hidden.sectionpadding 16px 14px 14pxfont-size 16pxbackground-color #fffcolor #666border-bottom 1px solid #eeeposition relative.section-titlecolor #000font-weight 700line-height 16px> .iconfontfloat rightcolor #ccc.deliverymargin-top 16pxfont-size 13pxline-height 18px.delivery-iconwidth 55pxfont-size 11pxmargin-right 10pxdisplay inline-blocktext-align centercolor #fffbackground-color #0097ffpadding 1px 0border-radius 4px.delivery-moneymargin-top 5px.activitymargin-top 16px.activity-itemmargin-bottom 12pxdisplay flexfont-size 13pxalign-items center&.activity-green.content-tagbackground-color rgb(112, 188, 70)&.activity-red.content-tagbackground-color rgb(240, 115, 115)&.activity-orange.content-tagbackground-color: rgb(241, 136, 79).content-tagdisplay inline-blockborder-radius 2pxwidth 36pxheight: 18pxmargin-right 10pxcolor #ffffont-style normalposition relative.mini-tagposition absoluteleft 0top 0right -100%bottom -100%font-size 24pxtransform scale(.5)transform-origin 0 0display flexalign-items centerjustify-content center.pic-wrapperwidth: 100%overflow: hiddenmargin-top 16px.pic-listwhite-space: nowrapfont-size: 0width 100%.pic-itemdisplay: inline-blockmargin-right: 6pxwidth: 120pxheight: 90px&:last-childmargin: 0.detailmargin-bottom -16px> lidisplay flexjustify-content space-betweenalign-items centermargin-right -10pxpadding 16px 12px 16px 0line-height 16pxbottom-border-1px(#ddd)font-size 13px> .boldfont-weight 700color #333&:last-childborder-none().splitwidth: 100%height: 16pxborder-top: 1px solid rgba(7, 17, 27, 0.1)border-bottom: 1px solid rgba(7, 17, 27, 0.1)background: #f3f5f7
</style>
这篇关于vue外卖二十二:商家详情-商家列表的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!