[英]Call function inside the Axios request (then) [Vuejs]
I am trying to call show
function inside Axios request, My Axios request inside another function as shown below: 我试图在Axios请求内调用show
函数,在另一个函数内调用My Axios请求,如下所示:
My Axios request inside Myfunction
: 我在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);
});
And function show
is in the method section: 功能show
在方法部分:
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. 现在,请记住,在实际调用该函数之前,请完成所有设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.