微信小程序页面跳转,url传参参数丢失问题

微信小程序页面跳转,url传参参数丢失问题

// pages/order/purchase/index.js
  // 跳转到采购订单详情
  toPurchaseOrderDetail(e) {
    // console.log(e, ' e');
    const detail = e.currentTarget.dataset.detail;
    wx.navigateTo({
      url:"/pages/order/purchase/orderDetail/index?detail=" + JSON.stringify(detail)
    });
  },


// pages/order/purchase/orderDetail/index.js
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(options,  '  options');
    // console.log(typeof options, ' typeof options');
    this.setData({
      // orderDetailsList: JSON.parse(options.detail),
      // finterid: JSON.parse(options.detail).FInterID
      orderDetailsList: options.detail,
      finterid: options.detail.FInterID
    });

    this.getFinterIdData();
  },

解决办法:使用encodeURIComponent():函数可把字符串作为 URI 组件进行编码

// pages/order/purchase/index.js
  // 跳转到采购订单详情
  toPurchaseOrderDetail(e) {
    const detail = encodeURIComponent(JSON.stringify(e.currentTarget.dataset.detail));
    wx.navigateTo({
      url:"/pages/order/purchase/orderDetail/index?detail=" + detail
    });
  },



// pages/order/purchase/orderDetail/index.js
  onLoad: function (options) {
    // console.log(options,  '  options');
    let orderDetailsList = JSON.parse(decodeURIComponent(options.detail));
    console.log(orderDetailsList, ' orderDetailsList');
    this.setData({
      orderDetailsList,
      finterid: orderDetailsList.FInterID
    });

    this.getFinterIdData();
  },

你可能感兴趣的:(微信小程序)