微信小程序之将轮播图设计为组件

在components文件夹上点右键,新建component,命名为swiper

然后将我们之前的代码都拷贝到对应文件中,

然后我们的页面要引用这个组件,

在pages\index\index.json中引入:

复制代码
{  
  "usingComponents": {
    "van-search": "@vant/weapp/search/index",
    "my-swiper":"../../components/swiper/swiper"
  }
}

在index.wxml中使用

复制代码
<view class="index-container">
  <view class="header">
    <van-search value="{{ value }}" shape="round" background="#fa2c19" placeholder="请输入搜索关键词" />
    <my-swiper
      circular="{{swiperOption.circular}}"
      autoplay="{{swiperOption.autoplay}}"
      interval="{{swiperOption.interval}}"
      duration="{{swiperOption.duration}}"
      indicator-dots="{{swiperOption.indicatorDot}}"
    > 
    </my-swiper>
  </view>
</view>

pages\index\index.js 中数据

复制代码
Page({
  data: {
      value: '',
      swiperOption: {
        indicatorDot: true,
        autoplay: true,
        interval: 3000,
        circular: true,
        duration: 1000,
        indicatorColor:'#fff',
        indicatorActiveColor:'#fa2c19'
      }    
  },
  
})

pages\index\index.wxss 中之前swiper和image的样式要删除掉

复制代码
.header {
  background-image: -webkit-linear-gradient(botton, #f1503B, #c82519 50%);
  background-image: linear-gradient(0deg, #f1503b, #c82519 50%);
  width: 100%;
  height: 190px;
  border-bottom-left-radius: 100%;
  border-bottom-right-radius: 100%;
}

这样就好了!!

意外:

我发现indicator-dots的属性值传递不下去,组件中设置了false,无论调用的时候用什么值,轮播图指示器都不显示,同样,组件中indicator-dots属性设置了true,无论调用的时候用什么值,都会显示指示器,而其他属性改变了是可以改变轮播图的运行的,如果有哪位刚好知道,请告知解惑,谢谢!

相关推荐
weixin_lynhgworld4 小时前
剧本杀小程序系统开发:构建剧本杀社交新生态
小程序
说私域4 小时前
基于定制开发开源 AI 智能名片 S2B2C 商城小程序的热点与人工下发策略研究
人工智能·小程序
weixin_lynhgworld4 小时前
陪诊小程序系统开发:让就医不再是一件难事
小程序
是一碗螺丝粉18 小时前
拯救你的app/小程序审核!一套完美避开审核封禁的URL黑名单机制
前端·javascript·微信小程序
weixin_lynhgworld1 天前
盲盒抽谷机小程序系统开发:从0到1的完整方法论
小程序
weixin_lynhgworld1 天前
短剧小程序系统开发:赋能创作者,推动短剧艺术创新发展
小程序
一匹电信狗1 天前
【C++】异常详解(万字解读)
服务器·c++·算法·leetcode·小程序·stl·visual studio
我叫黑大帅1 天前
微信小程序分包:告别加载慢,像拆快递一样简单!
前端·微信小程序
两个月菜鸟1 天前
vue+微信小程序 五角星
前端·vue.js·微信小程序
说私域1 天前
基于开源AI智能客服、AI智能名片与S2B2C商城小程序的微商服务优化及复购转介绍提升策略研究
人工智能·小程序