目录
点击轮播图跳转到微信小程序的问题
昨晚写了一个小程序首页,其中涉及到一个轮播,我把图片全部以数组的形式放在js中,官方文档只给了一个超链接,但是我使用的时候整个页面会变白然后跳转,给人一种很不舒服的感觉,所以决定在最终版本中继续修改完善代码:
首先找原因的代码如下:
<swiper class="index-banner" indicator-dots="{{true}}" circular="{{true}}" autoplay="{{true}}" interval="{{2000}}" duration="{{500}}"> <block wx:for="{{imgUrls}}" wx:key="{{item}}"> <navigator class="index-menu-item" url="{{item.url}}"> <swiper-item > <image src="{{item.icon}}" mode="aspectFill" class="slide-image"/> </swiper-item> </navigator> </block> </swiper>
轮播跳转到最终版本
我写了一个函数,xml如下:
<swiper class="index-banner" indicator-dots="{{true}}" circular="{{true}}" autoplay="{{true}}" interval="{{2000}}" duration="{{500}}"> <block wx:for="{{imgUrls}}" wx:key="{{item}}"> <swiper-item data-url="{{item.url}}" bindtap="changeURL"> <image src="{{item.icon}}" mode="aspectFill" class="slide-image"/> </swiper-item> </block> </swiper>
js如下,其中e…url为data-url="{{item.url}}"传递的参数:
changeURL: function (e) { wx.navigateTo({ url: `${e.currentTarget.dataset.url}`, success: function (res) { // success }, fail: function () { // fail }, complete: function () { // complete } }) },
微信小程序页面跳转失败原因简述
我在写点击跳转的时候,无法跳转到有 item 的页面,奇葩的是可以跳转到当前页面,相当于没有跳转。于是好奇心大增,查了一下官方文档,文档提示:
1.跳转需要用户确认,从2.3.0版本开始,跳转至其他小程序前会新增弹窗询问是否跳转,用户确认后才可跳转,若用户点击取消则会回调fail。
2.每个小程序可跳转的其他小程序数量限制为不超过10个。从2.4.0版本开始及指定日期(待定),开发者提交新的小程序代码时,若使用跳转其他小程序功能,需在代码配置中声明需要跳转的小程序列表,限制不超过10个,否则审核不通过。列表可在新版本发布时更新,不支持动态修改。配置方法见配置。调用此接口时,跳转必须在配置列表中,否则回调失败“${}”不在
这两个都不符合我的情况,查看了其他教程后,成功定位到了错误所在。
病因概述
跳转的路径没有在app.js中注册过,或者路径写错了
跳转的路径在 ,必须使用wx. 才能跳转到界面