<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        微信小程序實現天氣預報功能

        來源:懂視網 責編:小OO 時間:2020-11-27 22:11:20
        文檔

        微信小程序實現天氣預報功能

        本文實例為大家分享了微信小程序實現天氣預報功能的具體代碼,供大家參考,具體內容如下:這個案例是仿UC中天氣界面做的中間也有點出入,預留了顯示當前城市名字和刷新圖標的位置,自己可以寫下,也可以添加搜索城市。值得注意的是100%這個設置好像已經不好使了,可以通過獲取設備的高度通過數據綁定設置高度。地址:weather。界面主要分為四部分。第一部分;這里是預留的一塊可以自行添加補充下。<;view class="newTopView">;<。--左邊添加當前城市名字,點擊跳轉選擇城市 右邊添加刷新當前天氣-->;<;/view>。第二部分。
        推薦度:
        導讀本文實例為大家分享了微信小程序實現天氣預報功能的具體代碼,供大家參考,具體內容如下:這個案例是仿UC中天氣界面做的中間也有點出入,預留了顯示當前城市名字和刷新圖標的位置,自己可以寫下,也可以添加搜索城市。值得注意的是100%這個設置好像已經不好使了,可以通過獲取設備的高度通過數據綁定設置高度。地址:weather。界面主要分為四部分。第一部分;這里是預留的一塊可以自行添加補充下。<;view class="newTopView">;<。--左邊添加當前城市名字,點擊跳轉選擇城市 右邊添加刷新當前天氣-->;<;/view>。第二部分。

        本文實例為大家分享了微信小程序實現天氣預報功能的具體代碼,供大家參考,具體內容如下

        這個案例是仿UC中天氣界面做的中間也有點出入,預留了顯示當前城市名字和刷新圖標的位置,自己可以寫下,也可以添加搜索城市。值得注意的是100%這個設置好像已經不好使了,可以通過獲取設備的高度通過數據綁定設置高度。地址:weather

        界面主要分為四部分:

        第一部分

        這里是預留的一塊可以自行添加補充下

        <view class="newTopView">
        <!--左邊添加當前城市名字,點擊跳轉選擇城市 右邊添加刷新當前天氣-->
        </view>

        第二部分:

         <view class="topView">
         <view class="degreeView">
         <!--當前溫度-->
         <text class="degree">{{currentTemperature}}</text>
         <!--度數圖標-->
         <image class="circle" src="../../image/circle.png"></image>
         </view>
         <view class="detailInfo">
         <view class="degreeView">
         <!--夜間天氣情況-->
         <text class="detailInfoDegree">{{nightAirTemperature}}</text>
         <image class="detailInfoCircle" src="../../image/circle.png" />
         <text class="detailInfoLine">/</text>
         <!--白天天氣-->
         <text class="detailInfoDegree">{{dayAirTemperature}}</text>
         <!-- style優先級比class高會覆蓋class中相同屬性 -->
         <image class="detailInfoCircle" style="margin-left: 57rpx; margin-right: 40rpx" src="../../image/circle.png" />
         <!-- 當前天氣名字 -->
         <text class="detailInfoName">{{weather}}</text>
         </view>
         </view>
         </view>


        第三部分:

         <!-- 中間部分 -->
         <view class="centerView">
         <view class="centerItem" style="margin-right: 25rpx;">
         <image class="centerItemImage" src="../../image/leaf.png" />
         <!-- 相同屬性抽出來! -->
         <!--污染指數-->
         <text class="centerItemText" style="margin-left: 10rpx; margin-right: 10rpx">{{aqi}}</text>
         <!--污染指數對應name-->
         <text class="centerItemText">{{quality}}</text>
         </view>
         <view class="centerItem" style="margin-left: 25rpx">
         <image class="centerItemImage" src="../../image/wind.png" />
         <text class="centerItemText" style="margin-left: 10rpx; margin-right: 10rpx">{{windPower}}</text>
         <!--風-->
         <text class="centerItemText">{{windDirection}}</text>
         </view>
         </view>

        第四部分:

        <!-- 底部view -->
         <view class="bottomView">
         <!--數據返回的不是數組 在js中拼接的數組-->
         <block wx:for-items="{{list}}">
         <view class="bottomItemView">
         <image class="bottomImage" src="{{item.day_weather_pic}}" style="margin-bottom: 15rpx;" />
         <text wx:if="{{item.weekday == 1}}" class="bottomText">星期一</text>
         <text wx:elif="{{item.weekday == 2}}" class="bottomText">星期二</text>
         <text wx:elif="{{item.weekday == 3}}" class="bottomText">星期三</text>
         <text wx:elif="{{item.weekday == 4}}" class="bottomText">星期四</text>
         <text wx:elif="{{item.weekday == 5}}" class="bottomText">星期五</text>
         <text wx:elif="{{item.weekday == 6}}" class="bottomText">星期六</text>
         <text wx:else="{{item.weekday == 7}}" class="bottomText">星期日</text>
         <view class="degreeView" style="margin-top: 20rpx;">
         <text class="detailInfoDegree">{{item.night_air_temperature}}</text>
         <image class="detailInfoCircle" src="../../image/circle.png" />
         <text class="detailInfoLine">/</text> 
         <text class="detailInfoDegree">{{item.day_air_temperature}}</text>
         <!-- style優先級比class高會覆蓋class中相同屬性 -->
         <image class="detailInfoCircle" style="margin-left: 57rpx; margin-right: 40rpx" src="../../image/circle.png" />
         </view>
        </view>

        js

        //index.js
        //獲取應用實例
        var app = getApp()
        Page({
         data: {
         //加載狀態
         loadingHidden: false,
         //當前溫度
         currentTemperature: '',
         //夜間溫度
         nightAirTemperature: '',
         //白天溫度
         dayAirTemperature: '',
         //當前天氣
         weather: '',
         //污染指數
         aqi: '',
         //污染程度
         quality: '',
         //風力
         windPower: '',
         //風向
         windDirection: '',
         //因為數據返回不是數組所以要自己封裝一個數組
         list: [],
         height: 0,
        
        
         },
        
         onLoad: function () {
         console.log('onLoad')
         var that = this
        
         //100%好像不好使 可以獲取設備高度
         wx.getSystemInfo({
         success: function (res) {
         that.data.height = res.windowHeight;
         }
         })
        
         wx.getLocation({
         success: function (res) {
         //通過經緯度請求數據
         wx.request({
         //這個網站有免費API趕緊收藏
         url: 'http://route.showapi.com/9-5',
         data: {
         showapi_appid: '11697',
         showapi_sign: '6c0c15c5ec61454dac5288cea2d32881',
         //
         from: '5',
         lng: res.longitude,
         lat: res.latitude,
         //獲取一周情況 0是不獲取
         needMoreDay: '1',
         needIndex: '1'
         },
         success: function (res) {
         console.log(res)
         console.log(res.data.showapi_res_body.now.api)
         that.setData({
         //改變加載狀態
         loadingHidden: true,
        
         currentTemperature: res.data.showapi_res_body.now.temperature,
         nightAirTemperature: res.data.showapi_res_body.f1.night_air_temperature,
         dayAirTemperature: res.data.showapi_res_body.f1.day_air_temperature,
         weather: res.data.showapi_res_body.now.weather,
         aqi: res.data.showapi_res_body.now.aqi,
         quality: res.data.showapi_res_body.now.aqiDetail.quality,
         windPower: res.data.showapi_res_body.now.wind_power,
         windDirection: res.data.showapi_res_body.now.wind_direction,
         //拼接數組
         list: [
         {
         'day_weather_pic': res.data.showapi_res_body.f1.day_weather_pic,
         'weekday': res.data.showapi_res_body.f1.weekday,
         'day_air_temperature': res.data.showapi_res_body.f1.day_air_temperature,
         'night_air_temperature': res.data.showapi_res_body.f1.night_air_temperature
         },
         {
         'day_weather_pic': res.data.showapi_res_body.f2.day_weather_pic,
         'weekday': res.data.showapi_res_body.f2.weekday,
         'day_air_temperature': res.data.showapi_res_body.f2.day_air_temperature,
         'night_air_temperature': res.data.showapi_res_body.f2.night_air_temperature
         },
         {
         'day_weather_pic': res.data.showapi_res_body.f3.day_weather_pic,
         'weekday': res.data.showapi_res_body.f3.weekday,
         'day_air_temperature': res.data.showapi_res_body.f3.day_air_temperature,
         'night_air_temperature': res.data.showapi_res_body.f3.night_air_temperature
         },
         {
         'day_weather_pic': res.data.showapi_res_body.f4.day_weather_pic,
         'weekday': res.data.showapi_res_body.f4.weekday,
         'day_air_temperature': res.data.showapi_res_body.f4.day_air_temperature,
         'night_air_temperature': res.data.showapi_res_body.f4.night_air_temperature
         },
         {
         'day_weather_pic': res.data.showapi_res_body.f5.day_weather_pic,
         'weekday': res.data.showapi_res_body.f5.weekday,
         'day_air_temperature': res.data.showapi_res_body.f5.day_air_temperature,
         'night_air_temperature': res.data.showapi_res_body.f5.night_air_temperature
         },
         {
         'day_weather_pic': res.data.showapi_res_body.f6.day_weather_pic,
         'weekday': res.data.showapi_res_body.f6.weekday,
         'day_air_temperature': res.data.showapi_res_body.f6.day_air_temperature,
         'night_air_temperature': res.data.showapi_res_body.f6.night_air_temperature
         },
         {
         'day_weather_pic': res.data.showapi_res_body.f7.day_weather_pic,
         'weekday': res.data.showapi_res_body.f7.weekday,
         'day_air_temperature': res.data.showapi_res_body.f7.day_air_temperature,
         'night_air_temperature': res.data.showapi_res_body.f7.night_air_temperature
         }
        
         ]
         })
         }
         })
        
         }
         })
        
         }
        })
        
        

        wxss

        .container {
         display: flex;
         flex-direction: column;
         justify-content: space-between;
        
        }
        
        .newTopView {
         display: flex;
         flex-direction: row;
         justify-content: space-between;
        }
        
        /* 頭部樣式上半部分*/
        .topView {
         flex-direction: column;
         align-self: center;
         margin-top: -450rpx;
        }
        /*當前度數樣式*/
        .degreeView {
         flex-direction: row;
         position: relative;
        }
        /*當前溫度度數圖標*/
        .circle {
         width: 35rpx;
         height: 35rpx; 
         position: absolute;
         left: 130rpx;
        } 
        /*當前度數數組*/
        .degree {
         color: white;
         font-size: 130rpx
        }
        
        /*詳細View樣式*/
        .detailInfoView {
         flex-direction: row;
        }
        /*當前最高和最低溫度度數圖標*/
        .detailInfoCircle {
         width: 20rpx;
         height: 20rpx; 
         position: absolute;
         left: 30rpx;
        } 
        
        /*當前度數數組*/
        .detailInfoDegree {
         color: white;
         font-size: 30rpx
        }
        
        /*斜線*/
        .detailInfoLine {
         color: white;
         margin-left: 15rpx;
         font-size: 30rpx;
        }
        /*比如陰天 晴天,暴雨*/
        .detailInfoName {
         font-size: 30rpx;
         color: white;
         margin-left: 20rpx;
         align-self: center
        }
        
        /*中間view樣式*/
        .centerView {
         display: flex;
         flex-direction: row;
         margin-top: -550rpx;
         justify-content: center;
         align-items: center;
        }
        
        /*中間view分為兩個view*/
        .centerItem {
         display: flex;
         flex-direction: row;
         align-items: center;
         justify-content: center;
        }
        /*Item中圖片樣式*/
        .centerItemImage {
         width: 25rpx;
         height: 25rpx;
        }
        /*文字樣式*/
        .centerItemText {
         font-size: 28rpx;
         color: white;
        }
        
        /*底部view樣式*/
        .bottomView {
         margin-top: -200rpx;
         display: flex;
         flex-direction: row;
         justify-content: space-around;
         align-items: center;
        }
        
        
        .bottomItemView {
         display: flex;
         flex-direction: column;
         align-items: center;
         margin-bottom: 200rpx;
        }
        
        /*最近七天樣式*/
        .bottomImage {
         width: 70rpx;
         height: 70rpx;
        }
        
        .bottomText {
         font-size: 28rpx;
         color: white;
        }

        PS:

        開發者工具無法顯示問題:是因為View沒有獲得高度,默認個高度或者直接修改wxml中height高度即可。

        另外,本站在線工具小程序上有一款天氣查詢工具,還添加了城市選擇的功能,感興趣的朋友可以掃描如下小程序碼查看:

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        微信小程序實現天氣預報功能

        本文實例為大家分享了微信小程序實現天氣預報功能的具體代碼,供大家參考,具體內容如下:這個案例是仿UC中天氣界面做的中間也有點出入,預留了顯示當前城市名字和刷新圖標的位置,自己可以寫下,也可以添加搜索城市。值得注意的是100%這個設置好像已經不好使了,可以通過獲取設備的高度通過數據綁定設置高度。地址:weather。界面主要分為四部分。第一部分;這里是預留的一塊可以自行添加補充下。<;view class="newTopView">;<。--左邊添加當前城市名字,點擊跳轉選擇城市 右邊添加刷新當前天氣-->;<;/view>。第二部分。
        推薦度:
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 午夜无遮挡羞羞漫画免费| 精品无码免费专区毛片| 久久综合亚洲鲁鲁五月天| 亚洲国产成人精品电影| 中文字幕免费在线看线人 | 美女被免费视频网站a| 热久久精品免费视频| 亚洲欧美国产国产综合一区| 国产又黄又爽又猛免费app| 亚洲视频在线观看2018| 日本黄页网站免费| 羞羞视频网站免费入口| 亚洲А∨精品天堂在线| 久久精品成人免费网站| 亚洲成年人免费网站| 成年人视频在线观看免费| 精品视频免费在线| 亚洲欧洲日产国码av系列天堂| 黄网站免费在线观看| 亚洲国产综合自在线另类| 韩国日本好看电影免费看| 午夜在线免费视频 | 亚洲美女视频一区二区三区| 永久免费av无码不卡在线观看| 国产亚洲精品美女久久久| 未满十八18禁止免费无码网站 | 无人在线直播免费观看| 亚洲AV日韩AV一区二区三曲| 亚洲一区二区精品视频| 99热这里有免费国产精品| 亚洲91精品麻豆国产系列在线| 国产大片91精品免费观看男同| 中文字幕看片在线a免费| 亚洲成人在线免费观看| 国产免费av片在线无码免费看 | 免费无码黄网站在线看| 亚洲AV无码乱码在线观看代蜜桃| 免费人妻av无码专区| 99精品一区二区免费视频| 成a人片亚洲日本久久| 亚洲国产人成网站在线电影动漫|