The Asynchronous problem of main.js in vue Project

vue project, I have some asynchronous operations in main.js "s mounted, and routing is also loaded asynchronously. For example, when I set a settimeout, with a delay of 3s in main.js to visit a child routing page, I want to execute the mounted method of the corresponding vue file after performing all operations in the mounted of main.js (including asynchronous operations such as delay 3s, request interface, etc.). How should I do this?

Feb.14,2022

you can use the beforeEach hook function of router routing

const router = new Router({
    // ...
});

router.beforeEach((to, from, next) => {
    setTimeout(() => {
        // ...
        next();
    }, 3000);

    // ajax
    axios
        .get(url)
        .then(() => {
            // ...
            next();
        });
});
Menu