我试图在Axios请求中调用show
函数,My Axios请求在另一个函数内部,如下所示:
我在Myfunction
内的Axios请求:
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);
});
函数show
在方法部分:
show (workspace_info) {
alert("I am here");
},
但我收到一条错误消息:
TypeError: Cannot read property 'bind' of undefined
一个非常简单的方法是这样做:
app.show = function( workspaceInfo ) { // notice the camel case ;)
alert( 'I am here!' );
}
然后将其绑定到应用程序,如下所示:
app.show = app.show.bind( this ); // this is something we do a lot in React
最后,您可以使用它:
app.show( response );
现在,请记住,在实际调用函数之前,您已完成所有设置。