The applet this and that are detailed and simple examples, and that is detailed
In the applet. request ({}); after the method call is successful or fails, sometimes you need to obtain the page initialization data. If you use this. if the data is not obtained, undefiend is reported on the debugging page. The reason is that in javascript, this represents the current object and will change with the context during the execution of the program, in wx. request ({}); In the callback function of the method, the object has changed, so it is no longer wx. request ({}); Method object, and data attribute does not exist. The official solution is to copy the current object as follows:
Var that = this; // copy this object to the temporary variable that
You can use that. data in the success callback function to obtain the data.
However, there is another way, especially, to change the success callback function to a declaration method, as shown below:
success: res =>{ this.setData({ loadingHidden: true, hideCommitSuccessToast: false })}
In this way, this can be used directly to obtain data.
Here is a complete example:
Success: res => {if (res. data. code! = 0) {// submission failed this. setData ({loadingHidden: true, hiddenTips: false, tipsContent: res. data. message})} else {// submission successful this. setData ({loadingHidden: true, hideCommitSuccessToast: false}) subBtn = false; // timed, 3 seconds to disappear setTimeout () => {this. setData ({hideCommitSuccessToast: true}) wx. navigateBack ({delta: 2}) ;}, 2000 );}}
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!