//index.js //获取应用实例 const app = getApp() var defaultcity,getweather,gettemp,getwind,getpic,getdate Page({ data: { }, // onLoad:function(){ // var self = this; // wx.request({ // url: 'https://restapi.amap.com/v3/weather/weatherInfo', // data:{ // x:'',y:'', // 'key': '05dfde697d45489d927059b52a9ed8cd',//填入自己申请到的Key // 'city': '110101', // }, // header:{ // 'content-type': 'application/json' // }, // success:function(res){ // console.log(res.data); // } // }) // }, bindKeyInput:function(e){ defaultcity=e.detail.value }, search:function(e){ var that=this wx.request({ url:'https://restapi.amap.com/v3/weather/weatherInfo', data:{ x:'',y:'', 'key': '05dfde697d45489d927059b52a9ed8cd',//填入自己申请到的Key 'city': defaultcity, }, success:function(res){ getweather=res.data.lives[0].weather gettemp=res.data.lives[0].temperature getwind=res.data.lives[0].windpower // getpic=res.status.lives[0].dayPictureUrl getdate=res.data.lives[0].reporttime that.setData({ city:defaultcity,weather:getweather, temp:gettemp,windpower:getwind, reporttime:getdate }) } }) } })