小程序中條件渲染用法


 

有時完善內容顯示需要不同條件顯示不同內容

用到了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

歡迎關注,有問題一起學習歡迎留言、評論。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM