微信小程序事件bindtap实现页面跳转

index.wxml通过bindtap="getUrl"设置一个名为getUrl事件

<view class="tab-con">
      <view class="newsinfo" bindtap="getUrl">
        <view class="newsimg">
            <image src="../../images/1.png" mode="widthFix"></image>
        </view>
        <view class="con">
          <view class="title">
            <text>标题</text>
          </view>
          <view class="intro">
            <rich-text>近日,周迅工作室晒出了一组周迅出席时尚活动的照片</rich-text>
          </view>
        </view>        
      </view>
  </view>

index.js 获取点击的参数实现url跳转

getUrl: function (e) {
    // var id = e.currentTarget.dataset.id;//获取到绑定的数据
    //跳转传值
    wx.navigateTo({
      // url: '/pages/show/show?id=' + id,
      url: '/pages/show/show',
    })
  },

在这里插入图片描述
场景二点击跳转页面实现:
在这里插入图片描述

show.wxml

<view class="footer">
<text bindtap="urlfun" data-current="0" data-url="/pages/index/index">首页</text> 
<text bindtap="urlfun" data-current="1" data-url="/pages/news/news" style="color:#fff;background:#F8626E;">新闻</text>  
<text bindtap="urlfun" data-current="2" data-url="/pages/about/about" class='{{menuTapCurrent=="0"?"hover":""}}'>关于我们</text>   
</view>

show.js

data: {
    menuTagCurrent: '1',
    res:{}
  },
  urlfun: function (e){
    var myurl = e.target.dataset.url;
    var current = e.currentTarget.dataset.current;//获取到绑定的数据
    //改变menuTapCurrent的值为当前选中的menu所绑定的数据
    this.setData({
      menuTapCurrent: current
    });
    wx.switchTab({
      url: myurl,
      success: function () {
        console.log('跳转到news页面成功')
      },
      fail: function () {
        console.log('跳转到news页面失败');
      }
    })
  },
  • 4
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值