I am trying to call show
function inside Axios request, My Axios request inside another function as shown below:
My Axios request inside Myfunction
:
axios({
method: "Get",
timeout: 3000,
headers: {
..................
},
url: "https://XXXXXX/"
})
.then( function(response) {
console.log(response);
//Call function
app.show.bind(response);
})
.catch(function(error) {
console.log(error);
});
And function show
is in the method section:
show (workspace_info) {
alert("I am here");
},
but I got an error message:
TypeError: Cannot read property 'bind' of undefined
A very simple method would be to do this:
app.show = function( workspaceInfo ) { // notice the camel case ;)
alert( 'I am here!' );
}
And then bind it to the app like so:
app.show = app.show.bind( this ); // this is something we do a lot in React
Finally, you can use it like:
app.show( response );
Now, remember that you do all the setting up before you actually call the function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.