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

微信小程序列表点击跳转对应详情页[通俗易懂]效果展示:列表页js部分:onLoad:function(options){varthat=this;wx.request({url:’你的接口’,data:{ 接口参数},header:{‘content-type’:’ap…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

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.net/171123.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 《深入浅出 Java Concurrency》—锁紧机构(一)Lock与ReentrantLock

    《深入浅出 Java Concurrency》—锁紧机构(一)Lock与ReentrantLock

    2021年12月17日
    43
  • ntp时间服务器 时间同步

    具体两种模式1.服务器数量比较少,可以直接与公网时间服务器同步2.本地服务器较多,在本地设置时间同步服务器,  时间同步的两个命令ntpd :        校准时间,一点点的校准过来时间的,最终把时间慢慢的校正对。                     ntpd服务可以在修正时间的同时,修正cputick

    2022年4月9日
    122
  • java怎么求数组的和_java求和函数写法

    java怎么求数组的和_java求和函数写法Java经典题目之一,数组的各种求和,今天小编就用一些例子带大家了解一下其中详情。基础求和#includeusingnamespacestd;//数组求和//方法一:时间复杂度为O(n),额外空间为(n)intArraySum(intarr[],intn){intsum=0;for(inti=0;i{sum+=arr[i];}returnsum;}//方法二…

    2022年10月2日
    4
  • 解散群通知怎么写_家人微信群想解散通知怎么写「建议收藏」

    展开全部参考如bai下:1、明天我们这个群就要解du散了,请把这zhi个小礼物装dao在胸膛,它会化成你的信念专和力属量,鼓舞你去战胜狂风恶浪。2、不要说珍重,不要说再见,就这样,默默地离开。但愿,在金色的秋季,友谊之树上将垂下丰硕的果子,各位群友们珍重。3、你临别的微笑虽然只是短短的一瞬,但是摄在我心的底片上,却留下了永恒。我时时将它托在思念的掌心里,那形象是那么真切,那么清晰,群友们再见!4、…

    2022年4月3日
    419
  • 学习笔记 – EasyUI官方网站演示

    学习笔记 – EasyUI官方网站演示EasyUI官方网站演示撰写:2016/03/21更新:2016/04/07博客地址:http://www.cnblogs.com/gibbonnet/p/5362801.html演示地址:h

    2022年8月1日
    8
  • mybatis分页查询之sql server–mysql[通俗易懂]

    mybatis分页查询之sql server–mysql[通俗易懂]freemarker.beansKey”location”wasnotfoundoninstanceoforg.springframework.jdbc.UncategorizedSQLException.freemarker.beansKey”location”wasnotfoundoninstanceofcom.microsoft.sqlserver.jdbc.SQLServerException.sqlserver使用mybatis中分页查询时出现故障

    2022年5月12日
    35

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号