有些组件编译后的$taroCompReady为false
-
百度小程序开发,很多时候都遇到了
$taroCompReady
是false
的情况,大概下面几种情况- 父组件存在有if判断
- 兄弟组件中存在if判断
- 自己组件中存在if判断
尚不清除是否和这些if有关系,只是猜测,因为有时候删掉这些if就好了
export default function LpHot({ recommend }) { // 就是这样的if if (!recommend.length) return <View className='hide' />; return ( <View className='ui-box bgcf'> <View className='ui-box-hd'> <Text className='ui-box-title'>热门楼盘</Text> </View> <View className='ui-box-bd'> <View className='question-list'> {recommend.map(item => <LpCommItem item={item} key={item.id} />)} </View> </View> </View> ); }
编译后的LpHot
<block s-if="{{$taroCompReady}}"> <block s-if="{{!recommend.length}}"> <view class="hide"></view> </block> <view class="ui-box bgcf" s-else> <view class="ui-box-hd"><text class="ui-box-title">热门楼盘</text> </view> <view class="ui-box-bd"> <view class="question-list"> <lp-comm-item s-key="privateOriginal.id" s-for="loopArray49" s-for-item="item" s-for-index="_anonIdx2" compid="{{item.$compid__125}}"></lp-comm-item> </view> </view> </view> </block>
在开发者工具中的Swan Element中看到的lp-hot
<lp-hot compid="79"> </lp-hot>
很显然
$taroCompReady
为false
求助
-
把编译后的
s-if="{{$taroCompReady}}"
去掉,能否显示。按 debugger 指南 看看真正 setData 时的对象是什么,$taroCompReady 取值为多少。
-
发现好像根本没有执行到那个组件,控制台就报错了,还不清楚是什么原因导致了报错
Uncaught TypeError: e.trim is not a function file:///Users/moon/.swan-cli/vendor/swan-core/3.70.18/slaves/index.js 1 427593 {} e.event.on @ /Applications/百度开发者工…nts.js:formatted:39 ipcRenderer.on @ /Applications/百度开发者工…-map.js:formatted:1 emitTwo @ events.js:126 emit @ events.js:214
-
swan 的报错,重启开发者工具吧
-
@Cjj 在 有些组件编译后的$taroCompReady为false 中说:
把编译后的 s-if="{{$taroCompReady}}" 去掉
可以直接去掉吗,如果可以的话,为啥还要taroCompReady这个呢。公司搞的动态化方案,是dom渲染和js同步执行的,但是用了taro后第一帧就要等组件初始化完成了。