收藏
回答

导入同一文件封装的相似函数后,一个成功应用,一个报错?

//模块文件 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)


请问这是什么原因?


最后一次编辑于  03-17
回答关注问题邀请回答
收藏

1 个回答

  • 雷云
    雷云
    03-17

    虽然不知道为什么,但是把

    module.exports = {

    getWeatherDataNow : getWeatherDataNow,

    getWeatherDataForcast : getWeatherDataForcast

    }

    改为 :

    module.exports.WeatherDataNow = getWeatherDataNow;

    module.exports.WeatherDataForcast = getWeatherDataForcast;

    就可以了


    03-17
    赞同
    回复
登录 后发表内容
问题标签