Advantage: More convenient than URL delivery, or storage, or globalData
1: If the URL can not directly pass an Object to pass the serialization and deserialization operation, Trouble (ordinary single variable is very convenient and simple)
2: If the storage also trouble, but also set to use the time to get
3: GlobalData, although more than the above two seemingly more advantages, but this interactive data is very large, all day hanging in the globalData, while hanging up to the page can be accessed to (others say can be set to NULL, even if this is not More key on GlobalData)
But a lot of preload data is only a single rendering after not, and there is no need to mount on the globalData, so I think $preload useful
$preload use
A page preload data
Note: First preload and then the page routing jump, program routing jump Ah,
Do not use the Navigator component to bind a point-and-click event preload AH
data = { preloaddata: { name: ' Hello ', age : ' + ' } ; Methods = { Navigatetobpage () {this . $preload (' preload ', preloaddata)//First Wepy.navigateto ({ URL: ') /pages/b/b?sourcepage=${this.sourcepage} '} ); After }; ' Preload ' name a desired variable name in good // preloaddata data format, defined according to your needs
b page Receive
Must be in the OnLoad hook function to receive //options for URL parameters //Preloaddata for the previous page preload come over //specific print out to view Preloaddata specific What is onLoad (options, preloaddata) { if (preloaddata.preload && preloadData.preload.name) { Cosole.log (' Get the data from page a preload: ', preloaddata.preload); } };
If it is the component of a page triggered, then the preload to be flexible, the method can be a variety of
1: The method that defines the methods of the component directly inside methods = { Navigatetobpage () {this . $parent. $preload (' preload ', preloaddata)/ /First wepy.navigateto ({ URL: '/pages/b/b?sourcepage=${this.sourcepage} ' ); }//After }; //2: Communication interaction with the component methods = { Navigatetobpage () {this . $emit (' Emit_parent_preload ', preloaddata); } }; $emit an event to go out, trigger the parent page preload //a page in Events definition: events = { Emit_parent_preload (preloaddata) { this . $preload (' preload ', preloaddata); Wepy.navigateto ({ URL: '/pages/b/b?sourcepage=${this.sourcepage} ' );} }
I personally use the WEPY framework to develop small programs, is very fond of using prelaod and route navigation API such a combination way to pass data!
See here, do not put you also use, try ...
Wepy Framework API Pre-loading $preload This feature is so wide.