zhaojs
2023-07-13 70f5b82bc3fceafac2faf470280876b0eca6fac8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module.exports = {
    data() {
        return {}
    },
    onLoad() {
        // getRect挂载到$u上,因为这方法需要使用in(this),所以无法把它独立成一个单独的文件导出
        this.$u.getRect = this.$uGetRect
    },
    methods: {
        // 查询节点信息
        // 目前此方法在支付宝小程序中无法获取组件跟接点的尺寸,为支付宝的bug(2020-07-21)
        // 解决办法为在组件根部再套一个没有任何作用的view元素
        $uGetRect(selector, all) {
            return new Promise(resolve => {
                uni.createSelectorQuery().
                in(this)[all ? 'selectAll' : 'select'](selector)
                    .boundingClientRect(rect => {
                        if (all && Array.isArray(rect) && rect.length) {
                            resolve(rect)
                        }
                        if (!all && rect) {
                            resolve(rect)
                        }
                    })
                    .exec()
            })
        }
    },
    onReachBottom() {
        uni.$emit('uOnReachBottom')
    }
}