uniapp小程序系列-11首页顶部swiper文字+点击切页

1.创建swiper组件

2.写topBar

3.循环一下

<scroll-view scroll-x="true" >
			<view
				v-for='(item,index) in topBar'
				:key='index'
			>
				<text>{{item,name}}</text>
			</view>
		</scroll-view>
4.定义样式

<style scoped>
.scroll-content{
	width: 100%;
	height: 80rpx;
	white-space: nowrap;
}
.scroll-item{
	display: inline-block;
	padding:10rpx 30rpx;
	font-size:32rpx;
}
</style>
5.默认选中

.f-active-color{
	padding:10rpx 0;
	border-bottom:6rpx solid #49BDFB;
}
6.选中变色判断

设置索引

判断

<text :class='topBarIndex===index? "f-active-color":"f-color"'>{{item.name}}</text>
7.选中变色(加事件)

8.点击切页面

相当于整体的滑动,一整个页面的切换

1°添加swiper

2°不用手动添那么多,直接循环

9.上面点之后,下面跟着动(事件)

最外面的额swiper加事件

写方法

10.完成

点击哪个就切到哪页

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
UniApp是一个基于Vue.js的跨平台开发框架,可以用于开发iOS、Android、H5等多个平台的应用程序。而vue-awesome-swiper是一个基于Swiper的Vue组件,用于实现轮播图等滑动效果。 要在UniApp中使用vue-awesome-swiper,首先需要安装它。可以通过npm或者yarn进行安装,命令如下: ``` npm install vue-awesome-swiper --save ``` 安装完成后,在需要使用的页面中引入vue-awesome-swiper组件,并注册为全局组件或局部组件。例如,在`main.js`中全局注册: ```javascript import Vue from 'vue' import VueAwesomeSwiper from 'vue-awesome-swiper' import 'swiper/css/swiper.css' Vue.use(VueAwesomeSwiper) ``` 然后,在需要使用轮播图的页面中,可以直接使用`<swiper>`标签来创建轮播图。例如: ```html <template> <swiper :options="swiperOptions"> <swiper-slide v-for="(item, index) in swiperList" :key="index"> <img :src="item.imgUrl" alt=""> </swiper-slide> <div class="swiper-pagination" slot="pagination"></div> </swiper> </template> <script> export default { data() { return { swiperOptions: { autoplay: true, loop: true, pagination: { el: '.swiper-pagination', }, }, swiperList: [ { imgUrl: 'https://example.com/image1.jpg' }, { imgUrl: 'https://example.com/image2.jpg' }, { imgUrl: 'https://example.com/image3.jpg' }, ], } }, } </script> ``` 在上面的代码中,`swiperOptions`是轮播图的配置项,可以根据需要进行设置。`swiperList`是轮播图的数据列表,可以根据实际情况进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值