微信小程序 轮播图且跳转微信公众号文章

  • 在页面的 WXML 文件中,使用 swiper 组件来实现轮播图:

    <view class="container"> <view class="swiperBox"> <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" indicator-color="#9D9C9C" easing-function="linear" circular="true" indicator-active-color="#ffffff"> <block wx:for="{{bannerList}}" wx:key="unique"> <swiper-item> <image src="{{item.imgUrl}}" class="swiper-item" data-item="{{item}}" wx:if="{{item.imgUrl}}" catchtap="onSwiperTap"></image> <image src="../../assets/swiper.png" class="swiper-item" data-item="{{item}}" wx:else></image> </swiper-item> </block> </swiper> </view> </view>
  • 在上述代码中,bannerList 是一个数组,包含了轮播图的数据,每个数据对象需要有一个 imageUrl 字段,表示图片的地址。

  • indicator-dots 设置为 true 可显示轮播图的指示点。

  • autoplay 设置为 true 可自动播放轮播图。

  • circular 设置为 true 可实现循环播放。

  • js文件

    Page({
    data: {
    bannerList: [],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
    },
    onLoad() {
    // 获取轮播图的数据,可以通过接口请求或本地数据
    // 将数据设置到 bannerList 数组中
    },
    // 点击轮播图跳转
    onSwiperTap(e) {
    let url = e.target.dataset.item.articleUrl
    wx.navigateTo({
    url: '../article/index?url='+url,
    })

    复制代码
    },

    })

  • 新建一个article文件夹

    • wxml页面中

      <web-view src="{{url}}"></web-view>

  • js文件中

    Page({
    data: {
    url: ""
    },
    onLoad: function (options) {
    console.log(options,'kkkkkkk')
    this.setData({
    url: options.url,
    })
    }
    })

相关推荐
绝世唐门三哥19 小时前
uniapp系列-uniappp都有哪些生命周期?
vue.js·小程序·uniapp
人还是要有梦想的1 天前
如何开发小程序介绍
小程序·notepad++
陈思杰系统思考Jason1 天前
系统思考:推论阶梯与冰山模型具像化
百度·微信·微信公众平台·新浪微博·微信开放平台
roamingcode1 天前
支付宝小程序数据可视化避坑指南:@antv/f2 踩坑与最佳实践
信息可视化·小程序·canvas·antv
2501_915921431 天前
HTTP和HTTPS协议全面解析:技术原理与安全应用
安全·http·ios·小程序·https·uni-app·iphone
double_eggm1 天前
微信小程序2
微信小程序·小程序
是江迪呀2 天前
实时看大家都在干嘛?我靠一行监听函数,做了个轻互动小程序
前端·微信小程序
码视野2 天前
课后报名小程序 — 从需求到原型的全栈实践
小程序
打瞌睡的朱尤2 天前
微信小程序1~25
微信小程序·小程序
hnxaoli2 天前
win10小程序(十八)剪切板循环粘贴
python·小程序