当前位置:网站首页>微信小程序02-轮播图实现与图片点击跳转
微信小程序02-轮播图实现与图片点击跳转
2022-07-01 15:09:00 【蹦跶哒的王小哲】
实现效果:
前言
在小程序01中,已经学习了如何制作底部导航栏,本节让我们一起学习如何制作轮播图,以及点击轮播图完成页面跳转。
实现过程
注:(1)前期学习,我这里用的本地的图片,后期的话,会对接后端接口,动态获取数据,前期方便学习,就暂时用的本地图片。(2)关于图片跳转地址,因为前期其他页面还没写,所以我这里跳转的是切换 Tab,如果后期数据中有返回跳转链接,可以去掉 navigator 标签中的 open-type="switchTab" 属性。
1 在 index.wxml 文件中,增加以下代码:
<!-- 头部广告图 -->
<swiper class="top-banner" indicator-dots="{
{indicatorDots}}" autoplay="{
{autoplay}}" interval="{
{interval}}" duration="{
{duration}}">
<block wx:for="{
{images_list}}" wx:key="id">
<navigator url="{
{item.link}}" open-type="switchTab">
<swiper-item >
<image src="{
{item.image_url}}" class="slide-image"></image>
</swiper-item>
</navigator>
</block>
</swiper>2 在index.wxss 文件中增加轮播图的样式
.top-banner {
width: 100%;
height: 360rpx;
}
.slide-image {
width: 100%;
height: 100%;
}3,在index.js 文件中 增加 data 参数
Page({
data: {
autoplay: true,
indicatorDots: true,
interval: 3000,
duration: 1200,
images_list : [
{
"id": 1,
"image_url": "../../images/banner1.jpg",
"link": "../list/list"
},
{
"id": 2,
"image_url": "../../images/banner2.jpg",
"link": "../mine/mine"
},
],
},
// 事件处理函数
bindViewTap() {
wx.navigateTo({
url: '../logs/logs',
})
},
onLoad() {
},
})踩过的坑
按着网上的教程,给图片增加跳转链接后(如下图),图片不显示。

关于此问题的文档比较少,其中一篇说,navigator 标签放在 swiper-item 标签外面,于是我就试了试,代码改成如下图:

然后轮播图就可以正常显示了。
边栏推荐
- 深度分析数据在内存中的存储形式
- NPDP能给产品经理带来什么价值?你都知道了吗?
- 项目中字符串判空总结
- 厦门灌口镇田头村特色农产品 甜头村特色农产品蚂蚁新村7.1答案
- The first word of JVM -- detailed introduction to JVM and analysis of runtime data area
- Task.Run(), Task.Factory.StartNew() 和 New Task() 的行为不一致分析
- 《QT+PCL第九章》点云重建系列2
- Flink 系例 之 TableAPI & SQL 与 MYSQL 分组统计
- Opencv Learning Notes 6 -- image feature [harris+sift]+ feature matching
- cmake 基本使用过程
猜你喜欢

竣达技术丨多台精密空调微信云监控方案

The first technology podcast month will be broadcast soon

opencv学习笔记五--文件扫描+OCR文字识别

Opencv Learning Notes 6 -- image mosaic

What are the books that have greatly improved the thinking and ability of programming?

首届技术播客月开播在即

The State Administration of Chia Tai market supervision, the national development and Reform Commission and the China Securities Regulatory Commission jointly reminded and warned some iron ores

The first word of JVM -- detailed introduction to JVM and analysis of runtime data area

In hot summer, please put away this safe gas use guide!

Fix the failure of idea global search shortcut (ctrl+shift+f)
随机推荐
The markdown editor uses basic syntax
数据产品经理需要掌握哪些数据能力?
solidty-基础篇-结构体和数组,私有 / 公共函数,函数的返回值和修饰符,事件
After twists and turns, I finally found the method of SRC vulnerability mining [recommended collection]
[zero basic IOT pwn] reproduce Netgear wnap320 rce
QT capture interface is displayed as picture or label
tensorflow2-savedmodel convert to pb(frozen_graph)
[leetcode] 16. The sum of the nearest three numbers
Apk signature principle
TS报错 Don‘t use `object` as a type. The `object` type is currently hard to use
【锁】Redis锁 处理并发 原子性
点云重建方法汇总一(PCL-CGAL)
JVM第一话 -- JVM入门详解以及运行时数据区分析
opencv学习笔记六--图像拼接
The data in the database table recursively forms a closed-loop data. How can we get these data
JVM第二话 -- JVM内存模型以及垃圾回收
官宣:Apache Doris 顺利毕业,成为 ASF 顶级项目!
Day-02 database
Tableapi & SQL and MySQL data query of Flink
互联网医院系统源码 医院小程序源码 智慧医院源码 在线问诊系统源码