Uniapp开发鸿蒙购物项目实战教程:实现首页轮播图

过去几天的文章中我们讲过了如何创建跨平台项目,如何进行基础的布局、如何实现自定义导航栏等等,通过这一系列的文章教程,我们最终要实现一个购物app,今天我们要做购物应用首页的轮播图部分。

对于轮播图uniapp提供了相应的组件swiper,并且是支持鸿蒙应用的,这样就非常方便了。我们简单写一个有三页内容的轮播图,首先定义轮播图和每一个元素的样式:

.swiper{
width: 100%;
height: 140px;
}
.swiper-item{
width: 100%;
height: 100%;
display: block;
}

现在在页面上添加轮播图:

<swiper class="swiper">
  <swiper-item>
    <view class="swiper-item" style="background-color: red;">1</view>
  </swiper-item>
  <swiper-item> 
    <view class="swiper-item" style="background-color: yellow;">2</view>
  </swiper-item>
  <swiper-item>
    <view class="swiper-item" style="background-color: green;">3</view>
  </swiper-item>
</swiper>

看一下效果:

现在我们尝试为每一页内容添加图片,此处以一个swiper-item为例:

<swiper-item>
  <view class="swiper-item" >
    <image src="/static/banner1.jpg" style="width: 100%;height: 100%;"></image>
  </view>
</swiper-item>

这样一个基本的轮播图就初见雏形了,然后我们可以继续丰富一下它的内容,下面为大家列举一些常用的属性:

indicator-dots:是否显示面板指示点
indicator-color: 指示点颜色
indicator-active-color: 当前选中的指示点颜色
autoplay:是否自动切换
interval:自动切换时间间隔

下面放上以上属性的正确使用方法,以及轮播图的完整代码:

<swiper class="swiper" indicator-dots="true" indicator-color="#f8f8f8" indicator-active-color="#007aff" duration="3000" autoplay="true">
  <swiper-item>
    <view class="swiper-item" >
      <image src="/static/banner1.jpg" style="width: 100%;height: 100%;"></image>
    </view>
  </swiper-item>
  <swiper-item>
    <view class="swiper-item" >
      <image src="/static/banner2.jpg" style="width: 100%;height: 100%;"></image>
    </view>
  </swiper-item>
  <swiper-item>
    <view class="swiper-item" >
      <image src="/static/banner3.jpg" style="width: 100%;height: 100%;"></image>
    </view>
  </swiper-item>
</swiper>

以上就是关于的轮播图的教程分享,感谢您的阅读。

##鸿蒙三方框架##Uniapp##购物#

#harmonyos#
全部评论

相关推荐

点赞 评论 收藏
分享
06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务