uniapp 结合uview实现banner切换

uniapp yekong

uniapp小程序开发 结合uview 实现banner切换加接口调用
uniapp 结合uview实现banner切换

<template>
	<div class="swiper">
		<u-swiper :list="banner" height="100" @change="e => current = e.current" :autoplay="false">
			<view slot="indicator" class="indicator">
				<view class="indicator__dot" v-for="(item, index) in banner" :key="index"
					:class="[index === current && 'indicator__dot--active']">
				</view>
			</view>
		</u-swiper>
	</div>
</template>

<script>
	import {
		getbanner
	} from '@/config/api.js'
	import configs from '@/config/config.js'
	export default {
		data() {
			return {
				configs,
				banner: [],
				current: 0
			};
		},
		mounted() {
			this.getbanner()
		},
		methods: {
			getbanner() {
				var that = this;
				that.banner = []
				getbanner({}, {
					custom: {
						auth: true
					}
				}).then(res => {
					if (res.code == 1) {
						var d = res.data
						d.forEach((type) => {
							that.banner.push(configs.baseUrl + type)
						});
					}
				}).catch(err => {

				})
			},
		}
	};
</script>


<style lang="scss" scoped>
	.swiper {
		width: 710rpx;
		height: 200rpx;
		margin: 20rpx auto;
	}

	.indicator {
		@include flex(row);
		justify-content: center;

		&__dot {
			height: 6px;
			width: 6px;
			border-radius: 100px;
			background-color: rgba(255, 255, 255, 1);
			margin: 0 5px;
			transition: background-color 0.3s;

			&--active {
				background-color: rgba(229, 164, 20, 1);
			}
		}
	}

	.indicator-num {
		padding: 2px 0;
		background-color: rgba(0, 0, 0, 0.35);
		border-radius: 100px;
		width: 35px;
		@include flex;
		justify-content: center;

		&__text {
			color: #FFFFFF;
			font-size: 12px;
		}
	}
</style>

喜欢