文件结构和效果预览

index.wxml代码

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

icon属性官方文档

index.css代码

/**index.wxss**/.page {margin: 0rpx 0rpx 50rpx 50rpx;
}.top {display: flex;flex-direction: row;
}.input {width: 80%;background-color: gainsboro;
}.icon {width: 10%;
}.body {text-align: center;display: flex;flex-direction: column;
}.city {font-size: 100rpx;
}.today {font-size: 70rpx;
}.bottom {display: flex;flex-direction: row;align-items: center;text-align: center;
}.weather {font-size: 80rpx;width: 50%;
}.right {display: flex;flex-direction: column;
}.wind {font-size: 60rpx;
}.temp {font-size: 60rpx;font-family: Arial, Helvetica, sans-serif;
}

index.js代码

//index.js
var defaultcity, getweather, gettemp, getwind, getpic, city, weather, temp, wind
Page({data: {},//默认载入onLoad: function(e) {var that = thisdefaultcity = '北京'wx.request({url: 'https://api.map.baidu.com/telematics/v3/weather?output=json&ak=1a3cde429f38434f1811a75e1a90310c&location=' + defaultcity,success: function(res) {getweather = res.data.results[0].weather_data[0].weathergettemp = res.data.results[0].weather_data[0].temperaturegetwind = res.data.results[0].weather_data[0].windgetpic = res.data.results[0].weather_data[0].dayPictureUrlthat.setData({city: defaultcity,weather: getweather,temp: gettemp,wind: getwind,pic: getpic})}})},//获取输入bindKeyInput: function(e) {defaultcity = e.detail.value},//搜索城市search: function(e) {var that = thiswx.request({url: 'https://api.map.baidu.com/telematics/v3/weather?output=json&ak=1a3cde429f38434f1811a75e1a90310c&location=' + defaultcity,success: function(res) {getweather = res.data.results[0].weather_data[0].weathergettemp = res.data.results[0].weather_data[0].temperaturegetwind = res.data.results[0].weather_data[0].windgetpic = res.data.results[0].weather_data[0].dayPictureUrlthat.setData({city: defaultcity,weather: getweather,temp: gettemp,wind: getwind,pic: getpic})}})}})

百度地图API接口官网

注意请求第三方接口时需要加入合法request服务器域名

部分网址不支持https协议,需要勾选上不校验合法域名

微信小程序——通过百度API查询天气情况相关推荐

  1. 微信小程序使用百度api获取天气信息 —— 微信小程序教程系列(16)

    之前已经介绍过,如何使用百度地图api来获取地理位置信息 微信小程序的百度地图获取地理位置 -- 微信小程序教程系列(15) 下面介绍使用百度api来获取天气信息. 1> 第一步:先到百度开放平 ...

  2. 微信小程序利用百度api达成植物识别

    看完本文你可学会: 如何使用百度智能云 如何在微信小程序中去接入百度api,达成植物识别的效果 如何使用百度智能云? 官网:https://cloud.baidu.com 进入官网,在用户中心下选择图 ...

  3. 【微信小程序调用百度API实现图像识别功能】----项目实战

    本章主要讲述: 如何更快的上手小程序 如何搭建一个页面以及跳转到另一个页面 如何调用百度API接口实现图像识别技术 如何在微信小程序的后台添加合法域名 私信获取源码,有问题可以关注留言或私信,计算机毕 ...

  4. 微信小程序自动推送当天天气情况Java版

    针对网上小程序推送天气消息进行二次优化与细节调整,更快速与方便的进行完成自己功能的开发 注意全文是在别人代码基础之上做的二次优化 教程开始: 1.注册微信测试账号 第二步: 彩虹屁平台注册 拉代码 修 ...

  5. 微信小程序+OLAMI自然语言API接口制作智能查询工具--快递、聊天、日历等

    微信小程序最近比较热门,再加上自然语义理解也越来越被人关注,于是我想赶赶潮流,做一个小程序试试.想来想去快递查询应该是一种比较普遍的需求. 如果你也在通过自然语言接口做点什么,希望我的这篇博客能帮到你 ...

  6. 微信小程序项目实战之豆瓣天气

    概述 微信小程序项目实战之豆瓣天气 详细 代码下载:http://www.demodashi.com/demo/10943.html 一.准备工作 1.注册微信小程序 2.在小程序设置中设置reque ...

  7. 高德地图api调用demo_微信小程序----高德地图API实现的DEMO

    [实例简介] 微信小程序----高德地图API实现的周边,天气,路线规划,地址详情等的DEMO.简单的效果,问一下官方能不能不要乱涨积分,你们涨积分,作者被骂!我真的很失望,再这样,我就不上传资源了! ...

  8. 微信小程序利用百度AI实现扫描身份证获取信息功能

    目录 前言 百度端创建应用 实现过程 结语 前言 微信小程序集成百度图像识别功能,实现对上传或拍照的身份证进行扫描,并获取身份证信息. 百度端创建应用 访问网址https://login.bce.ba ...

  9. 微信小程序转百度小程序修改

    微信小程序转百度小程序修改 百度小程序很多兼容性问题已修复,具体细节请参考官方开发文档:https://smartprogram.baidu.com/docs/develop/fuctionlist/ ...

  10. 微信小程序页面搜索框查询(无后台接口情况下)

    微信小程序页面搜索框查询(无后台接口情况下) 效果图: wxml <view class="container"><view class="goodsl ...

最新文章

  1. 标题和描述需注意什么才更有利于SEO首页优化?
  2. asp.net listview 单元格文字颜色_Excel – 如何批量修改单元格中部分关键字的字体颜色?...
  3. XCode下的iOS单元测试
  4. 比特币创业公司Circle首获数字货币许可证
  5. paip.c++ 内存泄漏以及解决之道.
  6. 毕设项目 - 基于SSM的教师工作考核绩效管理系统(含源码+论文)
  7. 阿龙学堂-Java手机号码归属地查询
  8. 华为平板解锁工具_它已不再是个娱乐工具 华为平板M6升级版:MatePad 10.8上手图赏...
  9. 将数字金额转换为对应的中文大写金额
  10. linux命令一个减号,linux shell环境减号-的用途
  11. linux开启80和443,nginx 80和443同时做负载均衡
  12. The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals
  13. 阿里云服务器购买与配置(4)安装nginx
  14. Java中对象属性的初始化顺序
  15. Java面试宝典(2019版)
  16. 指数函数,幂函数记录
  17. java web 下拉列表_关于web中下拉列表的几种实现方法
  18. Distiller量化学习(1)
  19. (四)现代计算机系统的层次结构
  20. 大连海洋计算机专业校址,大连海洋大学有几个校区,哪个校区最好及各校区介绍...

热门文章

  1. border做三角符号
  2. jQuery easing动画效果扩展
  3. Tomcat 服务器状态监控显示PS Survivor Space 99%
  4. Pthreads线程的基本常识
  5. 从零单排PAT1015,1016,1017,1018
  6. FireFox 插件SQLite Manager 学习
  7. Vim自动补全插件-NeoComplCache
  8. 17.TCP/IP 详解卷1 --- TCP: 传输控制协议
  9. 6. Zend_Uri
  10. 18. JavaScript event 对象