A series of problem handling caused by the async of Vue

Source: Internet
Author: User

1, the original project using jquery implementation to Vue, calling the parameters of the interface Ajax nested calls, resulting in a second Axios request completely no response, even the request is not sent, it is very strange;

Solution: Listen for a property (the first time an AJAX request gets the parameters) whether the change, change and then call the second function can

Watch: {' param ': {handler: (val, oldval) = {monitor param (also can listen for changes inside Param)}, deep:true} } 2, the parameters before the request interface, need to be processed, to simplify the code call function return value assigned to this parameter, but because Vue is an asynchronous problem, it does not wait for the function to pass the value to the parameter and then send the request to execute simultaneously, resulting in the transfer of the parameter is the initial value, not processed;

The same can be used to listen, when the function is called, a variable value changes, and then listen to call AJAX requests;

Of course these can also use timer delay, but certainly not the best solution;

Hope to have a better solution to provide;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.