微信小程序根据java后台传的type值链接不同的页面
思路:在js点击事件函数中对后台传过来的type进行一个判断确认就好啦
上代码
wxml代码:
<view class='index-item-bg'> <view class='index-item'> <view class='index-item-box' wx:for="{{shortcutList}}" style='background-color:#b5d6f1' data-pos='{{index}}' bindtap='tiao'> <image class='index-item-box-image' src='{{icon}}'></image> <view class='icon-box-ctn'> <view class='index-item-box-title'>{{item.name}}</view> <view class='index-item-box-desc'>国家一级机器人培训单位</view> </view> </view> </view> </view>
这里利用wx:for生成了多个标签(如下图)如果不根据type值的话会始终跳往一个页面
bindtap='tiao'这是一个跳转
data-pos='{{index}}'这是获取下标值

js代码如下:
let pos = e.currentTarget.dataset.pos;获取下标值
let type = this.data.shortcutList[pos].type;获取type值
后台传的数据大概是这样子:
![]()
下面是js里面的跳转函数:
tiao: function (e) { let pos = e.currentTarget.dataset.pos; let type = this.data.shortcutList[pos].type; if (type == 5) { wx.navigateTo({ url: '../../../pages/teachers/faculty/faculty', }) } else if (type == 8) { wx.navigateTo({ url: '../../../pages/opus/opus', }) } else if (type == 1) { wx.navigateTo({ url: '../../../pages/about/profile/profile', }) } else if (type == 3) { wx.switchTab({ url: '../../../pages/trade/trade' }) } },
本人原创博客希望大家提出意见:

浙公网安备 33010602011771号