mixin.js 665 B

123456789101112131415161718192021222324252627282930
  1. module.exports = {
  2. data() {
  3. return {}
  4. },
  5. onLoad() {
  6. // getRect挂载到$u上,因为这方法需要使用in(this),所以无法把它独立成一个单独的文件导出
  7. this.$u.getRect = this.$uGetRect
  8. },
  9. methods: {
  10. // 查询节点信息
  11. $uGetRect(selector, all) {
  12. return new Promise(resolve => {
  13. uni.createSelectorQuery().
  14. in(this)[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. onReachBottom() {
  28. uni.$emit('uOnReachBottom')
  29. }
  30. }