微信小程序天气预报查询代码
时间: 2023-09-13 10:05:42 浏览: 685
以下是一个简单的微信小程序天气预报查询代码,你可以根据自己的需求进行修改:
1. 在 `pages/index/index.wxml` 文件中添加以下代码:
```xml
<view class="container">
<form bindsubmit="formSubmit">
<input type="text" name="city" placeholder="请输入城市名" />
<button type="submit">查询</button>
</form>
<view wx:if="{{weather}}">
<view>{{weather.city}}</view>
<view>{{weather.weather}}</view>
<view>{{weather.temp}}</view>
</view>
</view>
```
2. 在 `pages/index/index.js` 文件中添加以下代码:
```javascript
const app = getApp()
Page({
data: {
weather: null
},
formSubmit: function (e) {
let city = e.detail.value.city
wx.request({
url: 'https://v0.yiketianqi.com/api',
data: {
version: 'v61',
city: city
},
header: {
'content-type': 'application/json'
},
success: (res) => {
this.setData({
weather: res.data
})
}
})
}
})
```
3. 在 `app.js` 文件中添加以下代码:
```javascript
App({
globalData: {
userInfo: null
}
})
```
注意:需要在小程序后台配置域名 `v0.yiketianqi.com`。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)