wxData.js 550 B

1234567891011121314151617181920212223242526
  1. class WxData {
  2. constructor(component) {
  3. this.Component = component
  4. }
  5. getData(key) {
  6. const data = this.Component.data
  7. if (!key) return data
  8. if (key.includes('.')) {
  9. let keys = key.split('.')
  10. const tmp = keys.reduce((prev, next) => {
  11. return prev[next]
  12. }, data)
  13. return tmp
  14. } else {
  15. return this.Component.data[key]
  16. }
  17. }
  18. setData(data, cb = () => {}) {
  19. if (!data) return
  20. if (typeof data === 'object') {
  21. this.Component.setData(data, cb)
  22. }
  23. }
  24. }
  25. export default WxData