需求:有十几个接口,但是必须是按顺序请求这是几个接口
cityArr: [
"110100",
"110101",
"110102",
"110105",
"110106",
"110107",
"110108",
"110109",
"110111",
], // 城市编码
methods: {
/**
* @Event 方法
* @description: 获取天气信息
* */
async getWeather() {
this.tableData = []
for (let i = 0; i < this.cityArr.length; i++) {
await gaoDeWeather(this.cityArr[i]).then((res) => {
if (
Object.prototype.toString.call(res.data.lives[0]) ===
"[object Object]"
) {
this.tableData.push(res.data.lives[0]);
}
});
}
},
},
created() {
this.getWeather();
},
// gaoDeWeather 如下
/* 高 德 地 图 获 取 天 气 的 接 口 */
export function gaoDeWeather(city) {
return request({
url: "https://urlurlurl,
method: "get",
params: {
key: "key", // 请求服务权限标识
city: city, // 城市编码
extensions: null, // 气象类型 可选值:base/all。base:返回实况天气,all:返回预报天气
output: null, // 返回格式 (可选值:JSON,XML)
},
});
}
/* 高 德 地 图 获 取 天 气 的 接 口 */