Determining the exact moment a dynamic component finishes loading

Currently, I am dynamically loading various components in this manner:

const Page0 = () => import("@/components/pages/tutorial/Pages/Page0")
const Page1 = () => import("@/components/pages/tutorial/Pages/Page1")

There are additional pages similar to this one, which will be determined based on the route parameters.

I am curious about how to detect when a specific page has finished loading so that I can display a loading screen, and also how to know when there is a switch between pages.

This is how everything comes together:

<template>
    <div>
        <component :is="current_page"></component>
    </div>
</template>

<script>
    const Page0 = () => import("@/components/pages/tutorial/Pages/Page0/index.vue")
    const Page1 = () => import("@/components/pages/tutorial/Pages/Page1/index.vue")

    export default {
        scrollToTop:
            true,
        components:
            {
                Page0,
                Page1,
            },
        computed:
            {
                current_page ()
                {
                    return "Page" + this.page
                }
            },
        asyncData ({
            route, store, env, params, query, req, res, redirect, error
        })
        {
            return {
                page:
                    params.page
            }
        }
    }
</script>

Answer №1

How can one determine when a dynamic component has finished loading?

To signal that a component, whether dynamic or static, has fully loaded, you can utilize the @hook:mounted method.

For example:

<component :is="current_page" @hook:mounted="doSomething"></component>

View this codesandbox demo for further reference

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Establishing a deadline for Firestore's Node.js library

When using the Firestore Node.js library, I often find that some operations, like fetching a document, can take longer than expected, sometimes even several minutes. I am looking to set a timeout or deadline of around 20-30 seconds for these operations. ...

The functionality of .attachClickHandler() is not maintained when the page is refreshed or redirected

I've encountered an issue while trying to integrate a custom Google login button in my index.html file. Initially, everything functioned flawlessly upon page load, with console outputs 1, 2, and 3 appearing sequentially, followed by output 4 upon sign ...

Error: The variable YouTube has not been declared within this context / YouTube API

In my attempt to implement a search using the YouTube Data API, I have come up with the following code. The setup involves an express generated stack with jade. #player script. // 2. This code loads the IFrame Player API code asynchronously. ...

When running the test, the message "Unable to resolve all parameters for BackendService" is displayed

Upon executing the ng test command, the following error was displayed. This is my service specification: describe('BackendService', () => { beforeEach(() => { TestBed.configureTestingModule({ providers: [ { p ...

Adding an Ajax response to a div in HTML: A step-by-step guide

How can I add Ajax response to a div in my HTML code? Below is my ajax script: $(document).ready(function(){ $('.credit,.debit').change(function(){ var value=$(this).val(); $.ajax({ type:"POST", url:" ...

How to prevent page scrolling in an Android web browser

Struggling to prevent my website from scrolling on different devices. While it's relatively easy to achieve on desktop browsers using overflow: hidden;, I'm facing issues with my Android tablet where the page continues to scroll no matter what I ...

What is the best way to incorporate a JavaScript variable within jQuery?

How can I incorporate an input parameter from a JavaScript function into a jQuery command? function logInEmail(value){ var userEmail = $("input[name=" + value + "]").val(); if(userEmail.length == 0){ alert("Email field cannot be empty"); ...

Using ngFor in Angular 2-5 without the need for a div container wrapping

Using ngFor in a div to display an object containing HTML from an array collection. However, I want the object with the HTML node (HTMLElement) to be displayed without being wrapped in a div as specified by the ngFor Directive. Below is my HTML code snipp ...

Error in Laravel: The endpoint addproduct only supports POST requests, not GET

As a newcomer to Laravel, I am facing an issue when trying to post to a route without using any form for submission. My suspicion is that the problem lies within my controller. Below is the button code: <div class="button0"> <button ...

Is it feasible to utilize the translate function twice on a single element?

Using Javascript, I successfully translated a circle from the center of the canvas to the upper left. Now, my aim is to create a function that randomly selects coordinates within the canvas and translates the object accordingly. However, I'm encounter ...

Warning issued by npm during compilation: The template string expression is unexpected as there should be no curly braces in the

Getting an npm warning during compiling (Unexpected template string expression no-template-curly-in-string) import React from 'react'; const Card = ({name, email, id }) => { return ( <div className='tc bg-light-green dib b ...

Trouble with defining variables in EJS

Recently delving into the world of node development, I encountered an issue with my EJS template not rendering basic data. I have two controllers - one for general pages like home/about/contact and another specifically for posts. When navigating to /posts ...

the JavaScript anchor feature is malfunctioning

Steps to Play Back: To start, in the header section, select any of the links with anchors: ##bankaccount #pack #platform #acq ##scorecard ##intrade #form Next, scroll up to the top of the page Then, reload the page Actual Outcome: Upon reloading a page w ...

What could be the reason for my empty $routeProvider?

Question: I'm facing an issue with the $routeProvider in my code. Here's my configuration: $routeProvider .when('/language/:countryCode', routing) .when('/promotion/:promotionCode', routing) .otherwise ...

Using Angular to open a modal by invoking the href function

Current Project Context I am currently following a tutorial on CRUD operations with DataTables, but I am using Asp.Net WebApi with Angular for this project. At step 9 of the tutorial, it introduces partial views for pop-up windows. However, instead of us ...

File or directory does not exist: ENOENT error occurred while trying to scan 'pages'

Having trouble adding a sitemap to my nextjs app - when I go to http://localhost:3000/sitemap.xml, I get this error: Error: ENOENT: no such file or directory, scandir 'pages' https://i.sstatic.net/cxuvB.png The code in pages/sitemap.xml.js is a ...

Incorporating a file from a specific directory in AngularJS

Every time I execute /sites/all/themes/theme/js/controller.js $scope.template = 'partials/tpl.html' /sites/all/themes/theme/js/index.html <div ng-include='template'></div> /sites/all/themes/theme/js/partials/tpl.html & ...

Creating hyperlinks in JSON response from a REST API with AngularJS - A guide!

I have a web application built with AngularJS, JS, JQ, and HTML5. This app can send various HTTP methods to the project's RESTful Web Service and receive responses in JSON format. The response is structured like this: When displayed in a <pre> ...

Learn how to dynamically populate text fields with data when an option is selected from a dropdown menu that is populated from a database using Laravel and Ajax technologies

Basically, I've included a drop-down menu in my form that retrieves values from the database. The form itself contains input fields, some of which already have values saved in the database. I'm using the drop-down menu to automatically load these ...

Transforming JavaScript into TypeScript within an Angular 4 component class

Here is the Javascript code I currently have. I need to convert this into a component class within an Angular component. As far as I understand, the Character.prototype.placeAt() code is used to add a new method or attribute to an existing object. In this ...