uniapp使用createSelectorQuery如果里面有图片的话使用boundingClientRect计算出其盒子宽高的方法获取宽高不准确的解决方法

解决方案就是:

在img里面加一个@load="fn_imgload"方法,然后在方法里面调用这个计算宽高的方法即可。

 fn_imgload: function () {
            this.et_ui_init();
        },
 et_ui_init: function () {
            var that = this;
            that.pgdata.width = lsktl.ci.windowWidth;
            that.pgdata.height = lsktl.ci.windowHeight;
            const query = uni.createSelectorQuery().in(this);
            that.$nextTick(function () {
                query.select("#box-bottom").boundingClientRect();
                query.select("#box-title").boundingClientRect();
                query.exec(function (res) {
                    var ttheight = 0;
                    for (var i in res) {
                        console.info(res[i].height);

                        ttheight += res[i].height;
                    }
                    that.midbox.height = lsktl.ci.windowHeight - ttheight - 30;
                });
            });

        }

你可能感兴趣的:(uni-app)