Blame view

component/v2/utils/wxData.js 660 Bytes
d46806b9     结构调整
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class WxData {
  constructor(component) {
    this.Component = component
  }
  getData(key) {
    const data = this.Component.data
    if (!key) return data
    if (key.includes('.')) {
      let keys = key.split('.')
      const tmp = keys.reduce((prev, next) => {
        return prev[next]
      }, data)
      return tmp
    } else {
      return this.Component.data[key]
    }
  }
  setData(data) {
    return new Promise((resolve, reject) => {
      if (!data) return reject('no data to set')
      if (typeof data === 'object') {
        this.Component.setData(data, () => {
          resolve(data)
        })
      }
    })
  }
}

export default WxData