Axios不接受URL参数字符串

时间:2018-05-01 10:42:33

标签: javascript async-await axios es2017

为什么我会收到错误:

  

“”url“参数必须是string类型。接收类型undefined”

当我运行此代码时:
附:我也尝试使用此URL传递变量,但结果是相同的。

var axios = require('axios')();

module.exports = {
    async getJSONAsync(){


        let json = await axios.get('https://tutorialzine.com/misc/files/example.json');

        return json;
    }
};

注意:我在另一个具有await关键字的异步函数中使用此函数。 喜欢:

async begin() {

        try {
            let setup = new SetUp(this.bot);
            await testapi.getJSONAsync().then(function (json) {
                console.log(json)
            });
            let settings = await setup.prepareTest();
            let session = await settings.driver.getSession();
            logger.logDebug('Launching ' + this.test.name);

            return settings;
        }

        catch (e) {

            logger.logErr('Error when create settings for ' + this.test.name);
            throw e;

        }

    }

1 个答案:

答案 0 :(得分:2)

  require('axios')()

那将导入axios并直接使用no参数调用它,因此它会抱怨它所期望的url不会被传递。也许只是不在这里叫它?