index.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <el-row class="weather modular" :gutter="40" >
  3. <el-col :span="8" class="rowN">
  4. <el-image :src="weather1" fit="scale-down" />
  5. <div class="name">温度</div>
  6. <div class="num">
  7. {{data.temperature}}
  8. <div class="unit">℃</div>
  9. </div>
  10. </el-col>
  11. <el-col :span="8" class="rowN">
  12. <el-image :src="weather2" fit="scale-down" />
  13. <div class="name">湿度</div>
  14. <div class="num">
  15. {{data.sd}}
  16. <div class="unit">%RH</div>
  17. </div>
  18. </el-col>
  19. <el-col :span="8" class="rowN">
  20. <el-image :src="weather3" fit="scale-down" />
  21. <div class="name">PM2.5</div>
  22. <div class="num">
  23. {{data.aqiDetail.pm2_5}}
  24. <div class="unit">ug/m3</div>
  25. </div>
  26. </el-col>
  27. </el-row>
  28. </template>
  29. <script>
  30. import axios from 'axios'
  31. import weather1 from "@/assets/images2/温度.png";
  32. import weather2 from "@/assets/images2/湿度.png";
  33. import weather3 from "@/assets/images2/pm2.5.png";
  34. export default {
  35. name: "weather",
  36. data() {
  37. return {
  38. weather1: weather1,
  39. weather2: weather2,
  40. weather3: weather3,
  41. data:{
  42. aqiDetail:{}
  43. }
  44. };
  45. },
  46. created(){
  47. this.initData()
  48. },
  49. methods: {
  50. //初始化数据
  51. initData() {
  52. axios({
  53. method: 'get',
  54. url: 'https://smartpark.caih.com/dxapi/aliWeather?area=南宁',
  55. timeout: 3000,
  56. }).then(res =>{
  57. this.data = res.data.showapi_res_body.now
  58. }).catch(err =>{
  59. })
  60. },
  61. }
  62. };
  63. </script>
  64. <style lang="scss" scoped>
  65. .weather{
  66. height:100px;
  67. }
  68. .rowN {
  69. display: flex;
  70. flex-direction: row;
  71. align-items: flex-start;
  72. .el-image {
  73. width: 60px;
  74. margin-top:-1px;
  75. }
  76. .name {
  77. font-size: 20px;
  78. margin: auto 24px auto 12px;
  79. }
  80. .num {
  81. font-size: 36px;
  82. font-family: "DINAlternate-Bold";
  83. font-weight: 700;
  84. display: inline-block;
  85. margin: auto 24px auto 12px;
  86. .unit {
  87. font-size: 24px;
  88. font-family: "MicrosoftYaHei-Bold";
  89. font-weight: 700;
  90. display: inline-block;
  91. }
  92. }
  93. }
  94. </style>