打开weather.js,修改weeks数据,添加天气状况数据,代码如下

    1. Page({
    2. data:{
    3. city:"北京",
    4. area:"海淀",
    5. weather:"多云",
    6. temperature:"18℃",
    7. weeks:[
    8. { week:"周三",
    9. temp:{highest:"18℃",lowest:"12℃"},
    10. weather:"多云"
    11. },
    12. { week:"周四",
    13. temp:{highest:"16℃",lowest:"10℃"},
    14. weather:"晴"
    15. },
    16. { week:"周五",
    17. temp:{highest:"19℃",lowest:"13℃"},
    18. weather:"多云"
    19. },
    20. ]
    21. }
    22. })

    修改weather.wxml页面,添加天气图标,代码如下。

    1. <view class='icon'>
    2. <image wx:if="{{w.weather=='晴'}}" src="/public/imgs/sun.png" mode='widthFix' style='width:50rpx'></image>
    3. <image wx:else src="/public/imgs/cloud.png" mode='widthFix' style='width:50rpx'></image>
    4. </view>

    每个星期的天气图标有两张图片,通过wx:if判断天气是否是“晴”控制显示哪张图片

    1. <view class='container'>
    2. <image class='bg' mode='widthFix' src='/public/imgs/qntq-bg.png'></image>
    3. <text class='weather'>{{weather}}</text>
    4. <text class='city'>{{city}} {{area}}</text>
    5. <text class='temperature'>{{temperature}}</text>
    6. <view class='week-list'>
    7. <view class='week-item' wx:for="{{weeks}}" wx:for-item="w" wx:key="index">
    8. <view class='week'>{{w.week}}</view>
    9. <view class='icon'>
    10. <image wx:if="{{w.weather == '晴'}}" src="/public/imgs/sun.png" mode='widthFix'
    11. style='width:50rpx'></image>
    12. <image wx:else src="/public/imgs/cloud.png" mode='widthFix' style='width:50rpx'> </image>
    13. </view>
    14. <view class='temp'>{{w.temp.highest}}~{{w.temp.lowest}}C</view>
    15. </view>
    16. </view>
    17. </view>

    image.png