Applet project recovery disk (c) global variable parameter passing problem

Global variables parameter passing, use them in the right situation is indeed very convenient, any page can take to global variables, but it can not be abused, to cite two examples I used in the project:

 

1. Set a global variable userInfo , I used to store the login user all the information , this information needs to be used in other pages, saving a lot of things, this is the right way to do more with less;

There are some types of variables used to identify the page, this is not one by one example:

 

2. I set two variables in a global variable: 

 

Intended in the current page information obtained, want to click on a specific information page to make information available prior to transfer into it. If you look passed between only two pages, is feasible, but I have to use these two data transmission parameters in many pages, the situation is very gg.

 

Specific circumstances:

In the current page, I get a list of people I'm following and specific information, then I click on that person, index will be this index is 0 occupy, indexId will be occupied by the person's information:

 

 

Mass participation here is no problem.

 To this page, I click on a specific published under a section, at this time: index = 0 (I click on the piece subscript), indexId = specific piece of information I click on the (already different from before), still display normal, but when I retreat back to the user when the page:

 User-specific information is no!

 This page is still indexId user information in the access to information, but has changed, so basically there is no information, and use this information request interface error.

 

* When the number of pages you want to modify all global variables, not suitable for mass participation tool

 

Solution: pass when the jump page with url parameters

inDetails: function (E) {
     var index = e.currentTarget.dataset.index; 
    the console.log ( " enter the first few " , index);
     var MSG = the JSON.stringify ( the this .data.goodsArr [index]); / / take information currently required to 
    the console.log (MSG) 
    IF ( the this .data.status === ( " Yes " )) { 
    app.globalData.isBuy = to true ; 
    } 
    wx.navigateTo ({ 
      URL: ' .. / Details / Details? MSG = ' + MSG, // url this information into the parameter passing 
    }) 
  },

 

  the onLoad: function (Option) {
     var E = Option;
     var Good = the JSON.parse (e.msg)                              // reception parameters 
   }

 

 Change it after no mistake!

 

Guess you like

Origin www.cnblogs.com/xmjs/p/12592038.html