JJJJJ
JJJJJ
  • 发布:2018-12-24 19:26
  • 更新:2018-12-25 08:43
  • 阅读:13979

onReady和mounted的区别??有坑??

分类:uni-app

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


  • 今天写程序时候,遇到这个问题,感觉mounted比onReady还快执行,
  • 感觉onReady是页面在渲染v-show之后执行的
  • 而mounted还没有执行完v-show就执行了..
  • 
    <view v-show="goodsclass.length==0" v-for="(i,index) in 5" :key="index" class=" class-item">  
    {{index}}  
    </view>  
    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到底有啥区别哦,,方便以后避坑啊...或者说官方整理下全部最佳编码建议啊..  
2018-12-24 19:26 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com - 啦啦啦啦

我遇到过一个是获取节点,用mounted是null, 用onReady才能打印出东西来,在app中,所以推荐使用onReady

该问题目前已经被锁定, 无法添加新回复