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

  • 在页面的 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,
    })
    }
    })

相关推荐
2501_9339072134 分钟前
本凡科技提供的宁波小程序开发服务全面解决方案
科技·微信小程序·小程序
阿珊和她的猫41 分钟前
微信小程序静默授权异步问题的处理方案
微信小程序·状态模式·notepad++
左师佑图42 分钟前
微信小程序集成 Day.js 插件的完整解决方案
微信小程序·小程序
陈思杰系统思考Jason1 小时前
系统思考:结构性缺陷与企业波动
百度·微信·微信公众平台·新浪微博·微信开放平台
2501_933907211 小时前
本凡科技提供宁波小程序服务与定制解决方案
科技·微信小程序·小程序
计算机徐师兄1 小时前
Java基于SpringBoot的运动健康小程序【附源码、文档说明】
spring boot·小程序·运动健康·java运动健康小程序·运动健康小程序·java运动健康微信小程序·运动健康微信小程序
Xpower 171 小时前
OpenClaw实战:从零开发电商小程序(2)
人工智能·语言模型·小程序·gateway
2501_9339072110 小时前
宁波小程序开发服务与技术团队专业支持
科技·微信小程序·小程序
陈思杰系统思考Jason18 小时前
动态博弈中的系统思考
百度·微信·微信公众平台·新浪微博·微信开放平台
Refly18 小时前
【微信接入 OpenClaw 龙虾🦞】10分钟手把手教程完成接入,Claude 模型无限使用
前端·微信·github