I am creating a javascript function to use in glideapps, following this process. The function takes in a google maps api url as a string input, and returns the json file as a string output. Using the example from google, I creaced this test which works fine.
function test(request_url){
var axios = require('axios');
var config = {
method: 'get',
url: request_url,
headers: { }
};
var final = axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
})
return final}
When I use the same function in the code for the glideapp function, I get two errors. First, I got the error: Error: Module name "axios" has not been loaded yet for context: _. Use require([])
and addressed it by using var axios = require(['foo'], function (foo)
instead.
window.function=function(request_url){
var axios = require(['axios'], function (axios) {
//axios is now loaded.
});
var config = {
method: 'get',
url: request_url,
headers: { }
};
var final = axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
})
return final}
Now I get the error TypeError: axios(...).then is not a function
. How do I fix this? Thank you
Comments
Post a Comment