The simplest small program data monitoring, the simplest vuEX principle, to achieve cross-page communication (transfer)
Statement reproduced to: Jane books: the original address: www.jianshu.com/p/2ba137a02…
Code part:
// Simulate data changes periodicallystartWebSocket() {
setInterval(()=> { this.setChangedData(121212); }, 5000); }, // secondary page listener function addListener:function(callback) { this.callback = callback; }, // Data modified on the current pagesetChangedData: function(data) {
//this.data = data;
if(this.callback != null) {
this.callback(data);
}
}
Copy the code
Secondary page listening:
app.addListener(function(changedData) {
console.log(changedData);
});
Copy the code
The code is very simple, I have been studying how proxy implements data monitoring changes, but online tutorials are very complicated, this article in Jane book is very good, simple and clear explanation of the most basic way of data monitoring changes.