//我把这些写在onLoad()函数中了 let that = this; letBMap = new bamp.BMapWX({ //new一个插件的对象出来 ak: "填你自己的", });
// 抽离的思想 let success = function (res) { let string = console.log(res.currentWeather[0]); //{currentCity: "烟台市", pm25: "206", date: "周二 12月10日 (实时:8℃)", temperature: "12 ~ 2℃", weatherDesc: "多云转晴", …}
let city = res.currentWeather[0].currentCity; let pm25 = res.currentWeather[0].pm25; let date = res.currentWeather[0].date; let temperature = res.currentWeather[0].temperature; let weatherDdesc = res.currentWeather[0].weatherDdesc; }; BMap.weather({ success: success, //成功的话执行success函数 });