建议使用 uni-app 的 onReady代替 vue 的 mounted。

今天写程序时候,遇到这个问题,感觉mounted比onReady还快执行,

感觉onReady是页面在渲染v-show之后执行的

而mounted还没有执行完v-show就执行了..

{{index}}

onReady: function() {

SelectorQuery = uni.createSelectorQuery().select('#home_index_wapRightMenu')

SelectorQuery.boundingClientRect(data => {

this.wapMenuViewHeight = data.height

console.log(this.goodsclass.length);

console.log("data.height", data.height);

console.log(this.goodsclass.length);

}).exec()

},

或者

mounted: function() {

SelectorQuery = uni.createSelectorQuery().select('#home_index_wapRightMenu')

SelectorQuery.boundingClientRect(data => {

this.wapMenuViewHeight = data.height

console.log(this.goodsclass.length);

console.log("data.height", data.height);

console.log(this.goodsclass.length);

}).exec()

},

goodsclass是一个网络加载的数组,在页面加载的时候,这个数组长度是0,

这点代码在mounted下执行,data.height永远获取的是,没有渲染5个view的高度

onReady下无问题.data.height是渲染5个view之后的高度..

请问,,mounted和onReady到底有啥区别哦,,方便以后避坑啊...或者说官方整理下全部最佳编码建议啊..

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐