问题描述:
TP5 当后端
VUE 当前端
请求聚合数据天气接口
问题解决:
演示效果
前端 VUE 代码:
<template>
<div class="whether-tank">
<!--
根据城市查询生活指数 http://apis.juhe.cn/simpleWeather/life GET
参数名 类型 是否必填 说明
city string 是 要查询的城市名称/id,城市名称如:温州、上海、北京,需要utf8 urlencode
根据城市查询天气 http://apis.juhe.cn/simpleWeather/query GET
参数形式如上
天气各类查询表
http://apis.juhe.cn/simpleWeather/wids GET 无需额外参数
支持城市列表
http://apis.juhe.cn/simpleWeather/cityList GET 无需额外参数
1: el-table 里面图片的遍历 (template 用法)
2: v-for 双重循环
3: 遍历 json 对象 [ 里面有数组,有对象 ]
-->
<el-card class="box-card">
<div class="header">
<el-row>
<el-button type="primary" round @click="showPanel(1)">查询天气</el-button>
<el-button type="success" round @click="showPanel(2)">天气类型</el-button>
<el-button type="warning" round @click="showPanel(3)">支持城市查看</el-button>
</el-row>
<div>
<hr class="hr" />
</div>
</div>
<div class="bottom1" v-show="bottom1">
<div class="cityShow" v-show="cityShow">
<el-select v-model="cityInitials" placeholder="城市首字母" @change="letterChange(cityInitials)">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
</el-select>
<br /> <br />
<h3>请选择城市</h3>
<br /><br />
<p>
<span v-for="(c, index) in choosingCity" :key="index">
<span @click="potinCity(c)" class="cityNameChoose">{
{c}}</span>
<span> </span>
</span>
</p>
</div>
<div class="weatherShow" v-show="weatherShow">
<p>
<span class="info info1">{
{ currentQueryCity }} </span>
<span class="info info2">{
{ realtimeWeather.temperature }}℃</span>
<span class="info info3">{
{ realtimeWeather.info }}</span>
<span class="info info4">{
{ realtimeWeather.direct }}</span>
<span class="info info5">湿度: {
{ realtimeWeather.humidity }}%</span>
<span class="info info6">空气质量: {
{ realtimeWeather.aqi }}</span>
</p>
<br /><br />
<h2>未来 5天天气</h2><br /><hr />
<div class="future5">
<div v-for="(fu, index) in futureWeather" :key="index">
<p>{
{ fu.date }}</p>
<p>{
{ fu.temperature }}</p>
<p>{
{ fu.weather }}</p>
<p>{
{ fu.direct }}</p>
</div>
</div>
</div>
</div>
<div class="weatherType" v-show="bottom2">
<el-table :data="tableData" class="elTable">
<el-table-column prop="wid" label="序号" width="" align="center"></el-table-column>
<el-table-column prop="weather" label="天气类型" width="" align="center"></el-table-column>
<el-table-column label="图标" align="center">
<template slot-scope="scope">
<img :src="scope.row.bgImg" width="60" />
</template>
</el-table-column>
</el-table>
</div>
<div class="cities" v-show="bottom3">
<div v-for="(item, index) in cityArr" :key="index" :class="'city' + { index }">
<h3>{
{ item.title }}</h3>
<br />
<p >
<span v-for="(city, index) in item.lists" :key="index">{
{ city }} </span>
</p>
<br /><hr /><br />
</div>
</div>
<div class="errEle" v-show="errBtm">
<h3>Sorry, 请求有问题</h3>
</div>
</el-card>
</div>
</template>
<script>
export default {
name: 'weather',
mounted: function () {
this.getWeatherType()
}</