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

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

相关推荐
pearbing12 小时前
多平台发力:小程序搜索优化的实用策略指南
小程序·小程序搜索排名·小程序优化·小程序搜索排名优化·小程序搜索优化·小程序seo
2501_9151063212 小时前
Charles抓包怎么用 Charles抓包工具详细教程、网络调试方法、HTTPS配置与手机抓包实战
网络·ios·智能手机·小程序·https·uni-app·webview
00后程序员张13 小时前
Fastlane 结合 开心上架,构建跨平台可发布的 iOS 自动化流水线实践
android·运维·ios·小程序·uni-app·自动化·iphone
游戏开发爱好者813 小时前
iOS 性能测试的工程化方法,构建从底层诊断到真机监控的多工具测试体系
android·ios·小程序·https·uni-app·iphone·webview
计算机毕设指导613 小时前
基于Springboot+微信小程序流浪动物救助管理系统【源码文末联系】
java·spring boot·后端·spring·微信小程序·tomcat·maven
2501_9160088914 小时前
iOS App 混淆的真实世界指南,从构建到成品 IPA 的安全链路重塑
android·安全·ios·小程序·uni-app·cocoa·iphone
计算机毕设指导614 小时前
基于微信小程序的健康指导平台【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
wx_ywyy679814 小时前
同城跑腿小程序核心功能解析:多订单合并、智能计费与实时位置共享
小程序·跑腿小程序·小程序制作·同城小程序·同城服务小程序开发·跑腿小程序开发·外卖小程序开发
2501_9151063214 小时前
iPhone 耗电异常全面诊断指南,构建多工具协同的电量分析与优化体系
android·ios·小程序·https·uni-app·iphone·webview
han_hanker14 小时前
svg 可改颜色,但似乎不支持微信小程序
微信小程序·小程序·notepad++