dom.js 891 B

123456789101112131415161718192021222324252627
  1. export default Behavior({
  2. methods: {
  3. gettingBoundingClientRect(selector, all) {
  4. return new Promise((resolve, reject) => {
  5. try {
  6. wx.createSelectorQuery()
  7. .in(this)[all ? 'selectAll' : 'select'](selector)
  8. .boundingClientRect((rect) => {
  9. if (all && Array.isArray(rect) && rect.length) {
  10. resolve(rect);
  11. }
  12. else if (!all && rect) {
  13. resolve(rect);
  14. }
  15. else {
  16. reject();
  17. }
  18. })
  19. .exec();
  20. }
  21. catch (err) {
  22. reject(err);
  23. }
  24. });
  25. },
  26. },
  27. });