微信小程序-自定义组件

自定义一个swiper轮播.

 

 

index

index.wxml

1 <!--logs.wxml-->
2  <swiperBanner Height="450rpx" imgList="{{banners}}" url="picUrl"></swiperBanner>

 

 

components文件夹中的swiper_banner/index

index.json

导入路径为上两层的components文件夹中的swiper_banner/index

 

 

components/swiper_banner/index.js

复制代码
 1 Component({
 2   properties: {
 3     imgList: {
 4       type: Array,
 5       value: [],
 6       observer: function (newVal, oldVal) {
 7         this.setData({
 8           imgList: newVal
 9         })
10       }
11     },
12     url:{
13       type:String,
14       value:''
15     },
16     Height:{
17       type:String,
18       value:''
19     },
20     Width:{
21       type:String,
22       value:''
23     }
24   }
25 })
复制代码

components/swiper_banner/index.json

1 {
2   "component": true
3 }

components/swiper_banner/index.wxml

复制代码
1 <view class='swiper'>
2   <swiper indicator-dots="true" autoplay="true" interval="5000" duration="1000" style="height:{{Height}};">
3     <block wx:for="{{imgList}}" wx:key="prototype">
4       <swiper-item>
5         <image src="{{item[url]}}" class="slide-image" mode="aspectFill" />
6       </swiper-item>
7     </block>
8   </swiper>
9 </view>
复制代码

components/swiper_banner/index.wxss

1 .swiper image{
2   width: 100%;
3   height: 100%;
4 }

 

 

复制代码
1 {
2   "enablePullDownRefresh": true,
3   "backgroundColor": "#FB5D5D",
4   "onReachBottomDistance": 10,
5   "usingComponents": {
6     "swiperBanner": "../../components/swiper_banner/index"
7   },
8   "navigationBarTitleText": "log"
9 }
复制代码

 

 

示例代码如下:点击获取

 

posted @   Sunsin  阅读(1025)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示