You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
class WxData {
|
|
|
|
|
constructor(component) {
|
|
|
|
|
this.Component = component
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getData(key) {
|
|
|
|
|
const data = this.Component.data
|
|
|
|
|
if (!key)
|
|
|
|
|
return data
|
|
|
|
|
if (key.includes('.')) {
|
|
|
|
|
const 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
|