微信小程序带参的页面跳转

微信小程序构建新闻列表
微信小程序template模板的使用
微信小程序新闻详情页面效果实现

在之前实现了新闻列表页和详情页的效果,接下来需要从列表页点击item跳转到详情页,并携带item的postId。

post.wxml中添加onPostTap事件,并携带postId
在这里插入图片描述

 <view bindtap="onPostTap" data-postId="{{item.postId}}">

post.js中实现onPostTap事件

  onPostTap: function (event) {
    var postId = event.currentTarget.dataset.postid;
    // console.log("on post id is" + postId);
    wx.navigateTo({
      // url:"post-detail/post-detail"
      url: "post-detail/post-detail?id=" + postId
    })
  },

post-detail.js中接收postId

Page({
  data: {
  },
  onLoad: function(options) {
    var postId = options.id;
    console.log(postId)
  },
})
发布了446 篇原创文章 · 获赞 67 · 访问量 24万+

猜你喜欢

转载自blog.csdn.net/hongxue8888/article/details/104776358
今日推荐