weather.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <div class="box">
  3. <p class="boxCity">{{weatcherData.city}}市</p>
  4. <p class="boxWeather">{{weatcherData.wea}}<br>
  5. <div class="boxTemperature">
  6. {{weatcherData.tem}}°
  7. </div>
  8. </p>
  9. <!-- <p class="boxWind">{{weatcherData.win}}{{weatcherData.win_speed}}</p> -->
  10. </div>
  11. </template>
  12. <script>
  13. import axios from 'axios'
  14. export default {
  15. data(){
  16. return{
  17. weatcherData:{}
  18. }
  19. },
  20. mounted() {
  21. this.getWeather();
  22. this.timer = setInterval(() => {
  23. this.getWeather();
  24. }, 1000 * 60 * 60) //每小时调用一次
  25. },
  26. methods: {
  27. getWeather() { // 第三方天气api接口
  28. axios.get('https://yiketianqi.com/free/day', {
  29. params: {
  30. unescape: "1",
  31. appid: '66192398',
  32. appsecret: 'cqIyJ5ZP',
  33. // version: 'v91'
  34. }
  35. }).then(res => {
  36. console.log(res.data);
  37. if (res.data) {
  38. this.weatcherData = res.data;
  39. }
  40. }).catch(err => {
  41. console.log(err)
  42. })
  43. }
  44. }
  45. }
  46. </script>
  47. <style scoped>
  48. .box{
  49. display: flex;
  50. align-items: center;
  51. color: #fff;
  52. margin-right: 20rem;
  53. }
  54. .boxTemperature{
  55. font-size: 18rem;
  56. }
  57. .boxWeather{
  58. font-size: 14rem;
  59. margin: 0 0 0 15rem;
  60. }
  61. .boxWind{
  62. margin: 0 15rem 0 8rem;
  63. font-size: 14rem;
  64. }
  65. .boxCity{
  66. font-size: 16rem;
  67. }
  68. </style>