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

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

相关推荐

  1. 程序 公众文章

    2023-12-14 06:22:03       47 阅读
  2. 程序九宫格布局,

    2023-12-14 06:22:03       63 阅读
  3. 程序实现

    2023-12-14 06:22:03       37 阅读
  4. 程序

    2023-12-14 06:22:03       30 阅读
  5. 程序页面

    2023-12-14 06:22:03       63 阅读
  6. 程序webView

    2023-12-14 06:22:03       41 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-14 06:22:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-14 06:22:03       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-14 06:22:03       82 阅读
  4. Python语言-面向对象

    2023-12-14 06:22:03       91 阅读

热门阅读

  1. 前端传的true后端变false?

    2023-12-14 06:22:03       55 阅读
  2. 3D三维数据格式分类(种类/软件平台)

    2023-12-14 06:22:03       65 阅读
  3. react中使用craco自定义配置

    2023-12-14 06:22:03       57 阅读
  4. 前端打包工具之Webpack5

    2023-12-14 06:22:03       52 阅读
  5. FAQ:Inheritance篇 — virtual functions

    2023-12-14 06:22:03       51 阅读
  6. 数据分析用哪个系统

    2023-12-14 06:22:03       53 阅读
  7. lua脚本的基本语法,以及Redis中简单使用

    2023-12-14 06:22:03       66 阅读
  8. ChatGPT 技术架构设计与实践

    2023-12-14 06:22:03       63 阅读
  9. mac切换node版本

    2023-12-14 06:22:03       59 阅读
  10. 力扣120. 三角形最小路径和

    2023-12-14 06:22:03       56 阅读
  11. 工作中 docker 的使用积累

    2023-12-14 06:22:03       60 阅读
  12. uniapp 页面通信

    2023-12-14 06:22:03       68 阅读
  13. 华为实训课笔记

    2023-12-14 06:22:03       52 阅读