basic.js 689 B

123456789101112131415161718192021222324252627
  1. export const basic = Behavior({
  2. methods: {
  3. $emit(...args) {
  4. this.triggerEvent(...args);
  5. },
  6. set(data, callback) {
  7. this.setData(data, callback);
  8. return new Promise((resolve) => wx.nextTick(resolve));
  9. },
  10. getRect(selector, all) {
  11. return new Promise((resolve) => {
  12. wx.createSelectorQuery()
  13. .in(this)
  14. [all ? 'selectAll' : 'select'](selector)
  15. .boundingClientRect((rect) => {
  16. if (all && Array.isArray(rect) && rect.length) {
  17. resolve(rect);
  18. }
  19. if (!all && rect) {
  20. resolve(rect);
  21. }
  22. })
  23. .exec();
  24. });
  25. },
  26. },
  27. });