小程序中条件渲染用法

 

有时完善内容显示需要不同条件显示不同内容

用到了WX:if

        <text class="comments-title">最新评论</text>

        <view class="comments-box" wx:if="{{comments.length > 0}}">

            <view class="comments-list" wx:for="{{comments}}" wx:for-item="item" wx:for-index="i">

                <view class="comments-avatar"><image class="comments-avatar-img" src="{{item.avatar}}"/></view>

                <view class="comments-main">

                    <view class="comments-author">

                        <view class="comments-zan">{{item.likes}}</view>

                        <text>{{item.author}}</text>

                    </view>

                    <view class="comments-content">{{item.content}}</view>

                    <view class="comments-data">{{item.times}}</view>

                </view>

            </view>

        </view>

        <!-- 没有评论 -->

        <view class="not-comments" wx:else> 暂时还没有评论喔! </view>

 

文章来源:刘俊涛的博客

地址:http://www.cnblogs.com/lovebing

欢迎关注,有问题一起学习欢迎留言、评论。

原文地址:https://www.cnblogs.com/lovebing/p/9414971.html