当前位置:网站首页>微信小程序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 标签外面,于是我就试了试,代码改成如下图:
然后轮播图就可以正常显示了。
边栏推荐
- go-zero实战demo(一)
- Filter & (login interception)
- Fix the failure of idea global search shortcut (ctrl+shift+f)
- leetcode:329. 矩阵中的最长递增路径
- NPDP能给产品经理带来什么价值?你都知道了吗?
- 厦门灌口镇田头村特色农产品 甜头村特色农产品蚂蚁新村7.1答案
- 《QT+PCL第六章》点云配准icp系列3
- TypeScript: let
- Summary of empty string judgment in the project
- Build MySQL master-slave server under Ubuntu 14.04
猜你喜欢
The difference between arrow function and ordinary function in JS
[zero basic IOT pwn] reproduce Netgear wnap320 rce
Wechat official account subscription message Wx open subscribe implementation and pit closure guide
idea中新建的XML文件变成普通文件的解决方法.
竣达技术丨多台精密空调微信云监控方案
[leetcode] 16. The sum of the nearest three numbers
Task. Run(), Task. Factory. Analysis of behavior inconsistency between startnew() and new task()
The data in the database table recursively forms a closed-loop data. How can we get these data
openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题
It's settled! 2022 Hainan secondary cost engineer examination time is determined! The registration channel has been opened!
随机推荐
职场太老实,总被欺负怎么办?
首届技术播客月开播在即
Skywalking 6.4 distributed link tracking usage notes
基于价值量化的需求优先级排序方法
TS reports an error don't use 'object' as a type The `object` type is currently hard to use
Written on the first day after Doris graduated
购物商城6.27待完成
APK签名原理
[advanced ROS] lesson 5 TF coordinate transformation in ROS
JVM第二话 -- JVM内存模型以及垃圾回收
三十之前一定要明白的职场潜规则
Redis安装及Ubuntu 14.04下搭建ssdb主从环境
opencv学习笔记六--图像特征[harris+SIFT]+特征匹配
Error-tf.function-decorated function tried to create variables on non-first call
opencv学习笔记五--文件扫描+OCR文字识别
Introduction to MySQL audit plug-in
ArrayList 扩容详解,扩容原理[通俗易懂]
Quelle valeur le pdnp peut - il apporter aux gestionnaires de produits? Vous savez tout?
【LeetCode】16、最接近的三数之和
Solid basic basic grammar and definition function