uniapp里的mounted_onReady和mounted的区别??有坑??
建议使用 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到底有啥区别哦,,方便以后避坑啊...或者说官方整理下全部最佳编码建议啊..
更多推荐

所有评论(0)