2023 Summer "Mobile Software Development" Experiment Report
Name and student number? | |
---|---|
Which course does this experiment belong to? | Ocean University of China 23rd Summer "Mobile Software Development" |
Experiment name? | Experiment 2: Weather query applet |
blog address? | XXXXXX |
Github warehouse address? | XXXXXX |
(Note: Publishing the experiment report on the blog and publishing the code to github is a bonus but not mandatory)
1. Experimental goals
1. Master the server domain name configuration and temporary server deployment; 2. Master the usage of the wx.request interface.
2. Experimental steps
List the key steps of the experiment, code analysis, and screenshots.
Register an account
https://dev.qweather.com/
got it after k e y key key
api call method
https://devapi.qweather.com/v7/weather/3d?location=101010100&key=这里替换成你的key
Mini program configures server domain name
Find and configure in development management r e q u e s t request request legal domain name
Download Japanese weather icons
https://dev.qweather.com/docs/resource/icons/
and put it in the project
Selector
mode=region
You can directly display regional information
Complete static page
Add logical function
However, at this time, only the selected city text content can be obtained through picker, which needs to be converted into location ID before it can be used, so add the domain name on the WeChat public platformhttps://geoapi.qweather.com
getLocationId() {
return new Promise((resolve, reject) => {
let that = this;
wx.request({
url: 'https://geoapi.qweather.com/v2/city/lookup?',
data: {
location: that.data.region[1],
adm: that.data.region[0],
key: 'e21f318045b848e29f6b1b1634dbe163'
},
success: (res) => {
console.log("getLocationId", res.data);
that.setData({
locationId: res.data.location[0].id
});
resolve(); // 解析 Promise
},
fail: (error) => {
reject(error); // 拒绝 Promise 并传递错误
}
});
});
}
Complete writinglocationId
needs to be encapsulated into a promise object before it can be used.then()
method
3. Program running results
Default
After selecting the region
List the final running results of the program and screenshots.
4. Problem summary and experience
getWeather()
andgetLocationId()
have asynchronous problems, which cannot be solved using then(): encapsulategetLocationId()
into p r o m i s e promise promisephoto
Describe the problems encountered during the experiment and how they were solved. What are your gains and experiences, and what suggestions do you have for course arrangements?