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

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

相关推荐
大米饭消灭者2 天前
Taro是怎么实现一码多端的【底层原理】
微信小程序·taro
FliPPeDround4 天前
Vitest Environment UniApp:让 uni-app E2E 测试变得前所未有的简单
微信小程序·e2e·前端工程化
FliPPeDround4 天前
微信小程序自动化的 AI 新时代:wechat-devtools-mcp 智能方案
微信小程序·ai编程·mcp
吴声子夜歌4 天前
小程序——布局示例
小程序
码云数智-大飞4 天前
如何创建自己的小程序,码云数智与有赞平台对比
微信小程序
luffy54594 天前
微信小程序页面使用类似filter函数的wxs语法
微信小程序·小程序
Slow菜鸟4 天前
微信小程序开发(二)目录结构完全指南
微信小程序·小程序
陈思杰系统思考Jason4 天前
系统思考:自由职业背后的悖论
百度·微信·微信公众平台·新浪微博·微信开放平台
攀登的牵牛花4 天前
给女朋友写了个轻断食小程序:去老丈人家也是先动筷了
前端·微信小程序
前端小雪的博客.4 天前
【保姆级教程】uniAI 插件高效开发 uni-app 微信小程序(附实战案例)
微信小程序·uni-app·ai编程·uniai