//模块文件 home_api.js
function getWeatherDataNow(latitude,longitude){
let type = "now";
return getWeatherData(latitude, longitude, type);
}
function getWeatherDataForcast(latitude, longitude){
let type = "forecast";
return getWeatherData(latitude, longitude, type);
}
module.exports = {
getWeatherDataNow : getWeatherDataNow,
getWeatherDataForcast : getWeatherDataForcast
}
//在 pages/home/home.js 中使用
导入方式:
var weatherReq = require("./../../service/home_api.js");
........
//应用位置
onLoad: function(options) {
//1.读取位置信息
let that = this;
console.log(that);
wx.getLocation({
type: 'wgs84',
success: function(res) {
//根据位置信息获取天气信息与城市信息
weatherReq.getWeatherDataNow(res.latitude, res.longitude).then(
(weather_now) => {
console.log(weather_now);
});
weatherReq.getWeatherDataForecast(res.latitude, res.longitude).then(
(weather_forecast) => {
console.log(weather_forecast);
});
}
});
},
报错内容:
VM7979:1 thirdScriptError
weatherReq.getWeatherDataForecast is not a function;at pages/home/home onLoad function;at api getLocation success callback function
TypeError: weatherReq.getWeatherDataForecast is not a function
at success (http://127.0.0.1:63406/appservice/pages/home/home.js:51:20)
请问这是什么原因?