Home > front end >  Callback interface to return the global data access
Callback interface to return the global data access

Time:05-06

Such as the first to the console. The log can print out the data, and the second display res undefined, that is why, is there any way to make it can access to even the global access to?

CodePudding user response:

Because your fetchUsers is an asynchronous method, return is a Promise, just like you use directly $. Ajax or axios, asynchronous method return values, outside can not directly use, of course you outside the print, method is to order with you, will not finish fetchUsers execution, such as

Since you use the asynchronous method, the data associated with the operation, put together bai, design is necessary, async and await, and then in. Then, will need to be exposed in the value assigned to an attribute of the current class

CodePudding user response:

Is usually defined in the global value of a variable to receive the res, so global can use this value

CodePudding user response:

reference 1/f, bubble fish _ response:
because your fetchUsers is an asynchronous method, return is a Promise, just like you use directly $. Ajax or axios, asynchronous method return values, outside can not directly use, of course you outside the print, method is to order with you, will not finish fetchUsers execution, such as

Since you use the asynchronous method, the data associated with the operation, put together bai, design is necessary, async and await, and then in. Then, will need to be exposed the value assigned to the current class of an attribute for the

Specific how to operate

CodePudding user response:

refer to the second floor is fierce, response:
is usually in the most globally defined a variable to receive the value of the res, such global can use this value

Specific how to operate

CodePudding user response:

reference 1/f, bubble fish _ response:
because your fetchUsers is an asynchronous method, return is a Promise, just like you use directly $. Ajax or axios, asynchronous method return values, outside can not directly use, of course you outside the print, method is to order with you, will not finish fetchUsers execution, such as

Since you use the asynchronous method, the data associated with the operation, put together bai, design is necessary, async and await, and then in. Then, will need to be exposed the value assigned to the current class of an attribute for the

Specific how to operate
  • Related