手记

【备战春招】第11天首页拼团秒杀砍价促销活动组件开发

课程章节: 3-6 首页拼团秒杀砍价促销活动组件开发
课程讲师: CRMEB

课程内容:
1、首先创建拼团秒杀组件promotion.vue

<template>
	<view class="promotion">
		<view class="promotion-container">
			<view class="left">
				<navigator :url="list.imgList.list[0].info[3]" hover-class="none">
					<image :src="list.imgList.list[0].img" mode=""></image>
				</navigator>
			</view>
			<view class="right">
				<navigator :url="list.imgList.list[1].info[3]" hover-class="none">
					<image :src="list.imgList.list[1].img" mode=""></image>
				</navigator>
				<navigator :url="list.imgList.list[2].info[3]" hover-class="none">
					<image :src="list.imgList.list[2].img" mode=""></image>
				</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			list: {
				type: Object,
				default: () => {}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.promotion {

		&-container {
			display: flex;
			height: 260rpx;
			padding: 30rpx;
			justify-content: space-between;
		}

		.left {
			image {
				width: 260rpx;
				height: 260rpx;
			}
		}

		.right {
			display: flex;
			flex-direction: column;
			justify-content: ;

			image {
				width: 416rpx;
				height: 124rpx;

			}
		}
	}
</style>

2、在index.vue中应用,再在comments 中注册,在template中使用,并获取数据

<template>
	<view class="home">
		<view class="home-container">
			<Banner :list='swiperData'></Banner>
			<SubCategory :list='menusData'></SubCategory>
			<Promotion :list="promotionData"></Promotion>
		</view>
	</view>
</template>

<script>
	import Banner from './components/Banner.vue'
	import SubCategory from '/components/SubCategory.vue';
	import Promotion from 'components/Promotion.vue'
	export default {
		comments:{
			Banner,
			SubCategory,
			Promotion
		},
		data(){
			return {
				swiperData:{},
				menusData:{},
				promotionData
			}
		},
		onLoad() {
			this._getHomeData()
		},
		methods:{
			async _getHomeData(){
				const {status,data,msg} = await homeDataApi()
				if(status === this.API_STATUS_CODE.SUCCESS){
					console.log(status,data,msg)
					this.swiperData = data.swiperBg.default
					this.menusData = data.menus.default
					this.promotionData = data.activity.default
					
					app._initTabBar(data.tabBar.default)
				}else{
					uni.showToast({
						icon:'none',
						title:'首页数据获取失败,请刷新重试',
						duration:3000
					})
				}
			}
		}
	}
</script>

<style>
</style>
1人推荐
随时随地看视频
慕课网APP