Data update applet nails ------ monitor the parent component sub-assemblies

To listen to the data in app.js using a timer in the sub-assembly to monitor data changes app.js inside, there are many other ways people online, very good, but I was not able to understand their own to do this with a timer, the performance may not be so good. . .

1. app.js stored data, and acquires the value of the parent component changed.

The App ({ 
  GlobalData: { 
    lastRelVal: '', // need to monitor data 
  }, 
  // updated in real time data 
  setChangeData (Data) { 
    this.globaldata.lastRelVal Data = 
  } 
});

2. Change the data in the parent component.  

let app = getApp () // introduced app.js 
var lastRelVal = '' 
Page ({ 
  Data: { 

  }, 
  // page load 
  the onReady () { 
    this.setData () 
  }, 
  // change the value inside app.js 
  the setData () { 
    for (the let I = 0; I <= 10; I ++) { 
      lastRelVal = I 
      app.setChangeData (lastRelVal) 
    } 
  }, 
});

3. 1s taken every value in the subassembly app.js

app = getApp the let () 
the Component ({ 
  Data: { 

  }, 
  // page load 
  the onReady () { 
    this.setData () 
  }, 
  // received value app.js inside 
  didMount () { 
    // get every 1s app .js inside lastRelVal value 
    this.interval the setInterval = (() => { 
      the console.log ( "new value taken spacer 1s", app.globaldata.lastRelVal) 
    }, 1000) 
  }, 
});

 

Guess you like

Origin www.cnblogs.com/wgl0126/p/11479322.html