查天气
演示
到心知天气注册账号,并申请免费试用版,但14天有效期后能查询到的数据将会降级。
在产品管理中生成私钥key
上一节查快递课程在后端服务中添加了$api.service,现在主要添加
$exp.服务_心知天气
,$l.query = "?key=上面生成的私钥key&location=" + $w.encodeURIComponent(option.location) $api.request("https://api.seniverse.com/v3/weather/now.json" + $l.query) $l.x = $r.results[0] $api.request("https://api.seniverse.com/v3/weather/daily.json" + $l.query + "&days=8") $l.x.daily = $r.results[0].daily $api.request("https://api.seniverse.com/v3/air/daily.json" + $l.query + "&days=8") $r.results[0].daily.forEach('$l.x.daily[$index].air = $x') $l.x
把三次请求结果合并到临时变量中一起返回给前端。
展示
天气图标weatherIcon(多云、小雨等)有对应的背景图background-image,类名由”weatherIcon-" + code组成。