微信小程序-天气预报查询

废话不说,直接上源码

采用的接口是https://api.asilu.com/这个网站的

在这里插入图片描述

在这里插入图片描述

wether.js部分


var defaultcity, getweather, gettemp, getwind, getpic, getdate,updata
Page({
  data: {},
  onLoad: function(e) {
    defaultcity = '集美'
    this.weather()
  },
  bindKeyInput: function(e) {
    defaultcity = e.detail.value
  },
  search: function(e) {
    this.weather()
  },
  weather: function() {
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: 'https://query.asilu.com/weather/baidu?city='+ defaultcity,
      success: res => {
        console.log(res.data)
        
        getweather = res.data.weather[0].weather
        gettemp = res.data.weather[0].temp
        getwind = res.data.weather[0].wind+res.data.weather[0].w
        getpic =  res.data.weather[0].icon2+'.jpg'
        getdate =  res.data.weather[0].date
        updata=res.data.update_time
        this.setData({
          city: defaultcity,
          weather: getweather,
          temp: gettemp,
          wind: getwind,
          pic: getpic,
          date: getdate,
          utime:updata
        })
     
        wx.hideLoading()
      }
    })
  }
})

weather.wxml内容

<view class="page">
  <view class="top">
    <input placeholder="输入城市名进行搜索" bindinput="bindKeyInput"></input>
    <view class="icon">
      <icon type="search" size="25" bindtap="search" />
    </view>
  </view>
  <view class="body">
    <view class="city">
      <text>{{city}}</text>
    </view>
    <view class="today">
      <text>{{date}}</text>
    </view>
    <view>
      <image src="{{pic}}" mode="aspectFit" style="width: 400rpx; height: 400rpx" />
    </view>
  </view>
  <view class="bottom">
    <view class="weather">
      <text>{{weather}}</text>
      <view class="temp">
        <text>{{temp}}</text>
      </view>
    </view>
    <view class="right">
      
      <view class="wind">
        <text>{{wind}}</text>
      </view>
    </view>
  </view>

  <view class="ud">
      <text>更新时间:{{utime}}</text>
    </view>
</view>

weather.wxss内容

page {
  background-color: #ee818a;
  color: #fff;
}

.page {
  margin: 50rpx;
}

.top {
  display: flex;
  padding: 20rpx;
  flex-direction: row;
  background-color: #efefef;
  position: relative;
  margin-bottom: 20rpx;
  border-radius: 10rpx;
}

.input {
  width: 80%;
  font-size: 32rpx;
}

.icon {
  width: 10%;
  position: absolute;
  right: 0;
  bottom: 5rpx;
}

.body {
  text-align: center;
  display: flex;
  flex-direction: column;
}

.city {
  font-size: 80rpx;
}

.today {
  font-size: 34rpx;
}

.bottom {
  display: flex;
  flex-direction: row;
  align-items: center;
  text-align: center;
}

.weather {
  font-size: 38rpx;
  width: 50%;
}

.right {
  display: flex;
  flex-direction: column;
}

.wind {
  font-size: 40rpx;
}

.temp {
  font-size: 40rpx;
  font-weight: bold;
  font-family: Arial, Helvetica, sans-serif;
}

input {
  color: #333;
}
.ud{

 text-align: center;
  padding-top: 100px;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FJSAY

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值