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.

mixin.js 858 B

2 years ago
1234567891011121314151617181920212223242526272829303132
  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. // 目前此方法在支付宝小程序中无法获取组件跟接点的尺寸,为支付宝的bug(2020-07-21)
  12. // 解决办法为在组件根部再套一个没有任何作用的view元素
  13. $uGetRect(selector, all) {
  14. return new Promise(resolve => {
  15. uni.createSelectorQuery().
  16. in(this)[all ? 'selectAll' : 'select'](selector)
  17. .boundingClientRect(rect => {
  18. if (all && Array.isArray(rect) && rect.length) {
  19. resolve(rect)
  20. }
  21. if (!all && rect) {
  22. resolve(rect)
  23. }
  24. })
  25. .exec()
  26. })
  27. }
  28. },
  29. onReachBottom() {
  30. uni.$emit('uOnReachBottom')
  31. }
  32. }