微信小程序页面数据传输

index.js

Page({

  data: {

    person: [{

      id: 1,

      name: '小明',

      text: "小明什么也没干"

    },

    {

      id: 2,

      name: '小花',

      text: '小花什么也不知道'

    },

    {

      id: 3,

      name: '小燕',

      text: '小燕今天想吃豆腐鱼汤'

    },

    {

      id: 4,

      name: '小雅',

      text: '今天也要美美哒'

    },

    {

      id: 5,

      name: '小茵',

      text: '我的衣服又不够穿了'

    },

  ]

  },

  showInfo: function (e) {

    // console.log(e);

    var id = e.currentTarget.id  // 获取id

    var name = ''

    var text = ''

    var tp = this.data.person  // this.person无法获取到data的数据故加上data

    tp.forEach((item) => { // 遍历

      if (item.id == id) {

        // 获取person中的数据保存在变量中,方便页面传输数据

        name = item.name;  

        text = item.text

      }

    });

    wx.navigateTo({

      url: '/pages/chats-list/chat-list?id='+id+'&name='+name+'&text='+text,

    })

  },

})

index-two.wxml

<view class="all">

  <view class="info">

      <text id="name">{{name}}</text>

    </view>

  <view class="mes">

    <image class="img" src='/image/chat/headimg{{id}}.jpeg'></image>

    <view class="content"><text id="texts">{{content}}</text></view>

  </view>

</view>

index-two.js

Page({

  data: {

    name: null,

    content: null,

    id: 1,

    temp: []

  },

  onLoad: function (e) {

    var that = this

    console.log(e);

    that.setData({

      name: e.name,

      content: e.text,

      id: e.id

    })

  }

})

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值