温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用uniapp vue与nvue实现轮播图

发布时间:2021-12-29 16:46:33 来源:亿速云 阅读:455 作者:小新 栏目:开发技术

小编给大家分享一下如何使用uniapp vue与nvue实现轮播图,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

vue部分如下:

<template>
	<view class="">
		<!-- 轮播图组件 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular="">
			<block v-for="(item,index) in swipers" :key="index">
				<swiper-item>
					<view class="swiper-item" @tap="event(index)">
						<image :src="item.src"
						 lazy-load
						 ></image>
					</view>
				</swiper-item>
			</block>
		</swiper>
	</view>
</template>

nvue部分如下:

<template>
	<div>
		<!-- 轮播图组件 -->
		<slider :auto-play="true" :interval="3000" class="slider">
			<div  v-for="(item,index) in swipers" :key="index" @click="event(index)">
				<image class="image" resize="cover" :src="item.src"></image>
			</div>
			<indicator class="indicator"></indicator>
		</slider>
	</div>
</template>

nvue部分的css样式如下:

<style>
.slider,.image{
		width: 750px;
		height: 350px;
	}
	.indicator{
		position: absolute;
		right: 0;
		bottom: 0;
		width: 150px;
		height: 30px;
		background-color: rgba(0,0,0,0);
		item-color:rgba(255,255,255,0.5);
		item-selected-color: #FFFFFF;
	}
</style>

js部分如下:

vue与nvue的js写法是一样的

<script>
	export default {
		data() {
			return {
				swipers:[{src:"/static/images/demo/demo4.png"},
						{src:"/static/images/demo/demo4.png"},
						{src:"/static/images/demo/demo4.png"},
						{src:"/static/images/demo/demo4.png"}]
			}
		},
		methods: {
			event(index){
				console.log("点击了 index:"+index)
			}
		}
	}
</script>

效果图如下:

vue:

如何使用uniapp vue与nvue实现轮播图

nvue:

如何使用uniapp vue与nvue实现轮播图

以上是“如何使用uniapp vue与nvue实现轮播图”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI