前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >微信小程序列表点击跳转对应详情页[通俗易懂]

微信小程序列表点击跳转对应详情页[通俗易懂]

作者头像
全栈程序员站长
发布2022-09-23 21:29:25
1.4K0
发布2022-09-23 21:29:25
举报

大家好,又见面了,我是你们的朋友全栈君。

2020/9/1:这种写法能实现但是用了多次缓存,后面发现其实是可以用自定义属性来传参的,具体有空我会写出来

效果展示:

微信小程序列表点击跳转对应详情页[通俗易懂]
微信小程序列表点击跳转对应详情页[通俗易懂]
微信小程序列表点击跳转对应详情页[通俗易懂]
微信小程序列表点击跳转对应详情页[通俗易懂]

列表页js部分:

onLoad: function(options) {

var that = this;

wx.request({

url: ‘你的接口’,

data: {

接口参数

},

header: {

‘content-type’: ‘application/json’, // 默认值

},

success: function (res) {

console.log(res.data);

that.setData({

你定义的变量名: res.data,

})

}

})

},

跳转详情页方法

viewDetail: function(e) {

let newsid = e.currentTarget.dataset.id || ”;

let newsTitle = e.currentTarget.dataset.newstitle || ”;

let newsAuthor = e.currentTarget.dataset.newsauthor || ”;

let newsDescription = e.currentTarget.dataset.newsdescription || ”;

let newsCreateTime = e.currentTarget.dataset.newscreatetime || ”;

let newsContentText = e.currentTarget.dataset.newscontenttext || ”;

let newsInfoSource = e.currentTarget.dataset.newsinfosource || ”;//你想传递的值

//放入缓存

wx.setStorage({

key: ‘你定义key的名程’,

data: {

newsid,

newsAuthor,

newsTitle,

newsDescription,

newsCreateTime,

newsContentText,

newsInfoSource

},

success: function () {

wx.navigateTo({

url: ‘../news_home/Detail/Detail?newsid=’ + newsid + “&newsTitle” + newsTitle + “&newsAuthor” + newsAuthor

+ “&newsDescription” + newsDescription + “&newsCreateTime” + newsCreateTime + “&newsContentText” + newsContentText

+ “&newsInfoSource” + newsInfoSource

})

}

})

},

列表页wxml:

用data-绑定传递

<view class=” bindtap=’viewDetail’ data-newsid='{ {item.newsid}}’ data-newstitle='{ {item.Title}}’ data-newsauthor='{ {item.Author}}’ data-newsdescription='{ {item.Description}}’ data-newscreatetime='{ {item.CreateTime}}’ data-newscontenttext='{ {item.ContentText}}’ data-newsinfosource='{ {item.InfoSource}}’>

<view style=”width:100%”>标题:{ {item.Title}}</view>

<view style=”width:100%”>作者:{ {item.Author}}</view>

<view style=”width:100%”>发布时间:{ {item.CreateTime}}</view>

</view>

详情页js:

从缓存中拿取数据

onShow: function () {

let that = this;

// 从缓存中获取

wx.getStorage({

key: ‘你定义key的名字’,

success: function (res) {

that.setData({

newsTitle: res.data.newsTitle,

newsAuthor:res.data.newsAuthor,

newsDescription:res.data.newsDescription,

newsCreateTime:res.data.newsCreateTime,

newsContentText:res.data.newsContentText,

newsInfoSource:res.data.newsInfoSource

})

},

})

},

详情页xwml:

<view>{ {newsInfoSource}}</view>

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/171123.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
数据库一体机 TData
数据库一体机 TData 是融合了高性能计算、热插拔闪存、Infiniband 网络、RDMA 远程直接存取数据的数据库解决方案,为用户提供高可用、易扩展、高性能的数据库服务,适用于 OLAP、 OLTP 以及混合负载等各种应用场景下的极限性能需求,支持 Oracle、SQL Server、MySQL 和 PostgreSQL 等各种主流数据库。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档