| | |
| | | <title>天气</title> |
| | | <!-- axios --> |
| | | <script src='../map/lib/axios.js'></script> |
| | | <script type="text/javascript" charset="utf-8" src="http://webapi.amap.com/maps?v=1.3&key=xxxxxx&plugin=AMap.Autocomplete,AMap.PlaceSearch"></script> |
| | | <script type="text/javascript" charset="utf-8" |
| | | src="http://webapi.amap.com/maps?v=1.3&key=xxxxxx&plugin=AMap.Autocomplete,AMap.PlaceSearch"></script> |
| | | <script src="https://cdn.jsdelivr.net/npm/vue@2.6.12"></script> |
| | | <style> |
| | | #weather{ |
| | | #weather { |
| | | font-weight: 400; |
| | | opacity: 0.7; |
| | | font-size: 14px; |
| | |
| | | weathers: { |
| | | nowWeather: '', |
| | | highTemperature: '', |
| | | lowTemperature: '', |
| | | lowTemperature: '', |
| | | }, |
| | | nowTime: { |
| | | year: '', |
| | |
| | | this.nowTime.year = (new Date()).getFullYear(); |
| | | this.nowTime.month = (new Date()).getMonth(); |
| | | this.nowTime.day = (new Date()).getDay(); |
| | | this.nowTime.hour = (new Date()).getHours() < 10? '0' + (new Date()).getHours():(new Date()).getHours(); |
| | | this.nowTime.minute = (new Date()).getMinutes() < 10? '0' + (new Date()).getMinutes():(new Date()).getMinutes(); |
| | | this.nowTime.second = (new Date()).getSeconds() < 10? '0' + (new Date()).getSeconds():(new Date()).getSeconds(); |
| | | this.nowTime.hour = (new Date()).getHours() < 10 ? '0' + (new Date()).getHours() : (new Date()).getHours(); |
| | | this.nowTime.minute = (new Date()).getMinutes() < 10 ? '0' + (new Date()).getMinutes() : (new Date()).getMinutes(); |
| | | this.nowTime.second = (new Date()).getSeconds() < 10 ? '0' + (new Date()).getSeconds() : (new Date()).getSeconds(); |
| | | }, |
| | | getWeather(){ |
| | | getWeather() { |
| | | var that = this; |
| | | var url = `http://wthrcdn.etouch.cn/weather_mini?city=${this.city}` |
| | | axios.get(url).then((res)=>{ |
| | | axios.get(url).then((res) => { |
| | | var data = res.data.data, |
| | | nowDay = data.forecast[0]; |
| | | nowDay = data.forecast[0]; |
| | | that.weathers.nowWeather = nowDay.type; |
| | | that.weathers.highTemperature = nowDay.high.slice(3); |
| | | that.weathers.lowTemperature = nowDay.low.slice(3); |
| | |
| | | setInterval(() => { |
| | | this.getNewTime(); |
| | | }, 1000); |
| | | setTimeout(() => { |
| | | this.getWeather(); |
| | | }, 200); |
| | | this.getWeather(); |
| | | } |
| | | }) |
| | | </script> |