Display a webpage once its design is completely loaded in Nuxt

I have implemented a layout for my admin pages that displays user information in a consistent format, eliminating the need to fetch this data every time the page reloads.

However, I am facing an issue where the page does not wait for the layout to fully load before querying user information.

myLayout.vue

beforeMount() {
    // retrieving user info from the server using Vuex action
}

myPage.vue

layout: "myLayout"
...
mounted() {
    // fetching user info from the Vuex store
}

In this scenario, I anticipate beforeMount to be executed first in myLayout.vue,

but myPage.vue proceeds and triggers mounted before the Vuex action completes.

As a result, the lifecycle follows:

layout's beforeMount -> page's beforeMount -> page's mounted -> layout's mounted

due to the page not waiting for the layout's beforeMount to be finished.

Is there a way to delay the mounting of a page until after the layout has been completely loaded?

Answer №1

If you want to implement a middleware on your Layout, you can do so by adding it to run before the layout and consequently, your page.

export default {
  ...
  async middleware({ store }) {
    await store.dispatch('fetch-some-data-with-vuex')
  },
  ...
}

For more information, please visit: https://nuxtjs.org/docs/2.x/directory-structure/middleware/

Answer №2

This is my unique solution.

The Nuxt component responsible for rendering the page is only mounted once the loading process is completed. I have implemented this by utilizing a variable along with a conditional statement.

layout.vue

<template>
  <Nuxt v-if="isLoaded" />
</template>

<script>
export default {
  data () {
    return {
      isLoaded: false,
    }
  },
  async created () {
    // perform necessary tasks

    this.isLoaded = true;
  },
}
</script>

Answer №3

If you want to achieve this, you can follow these steps:

Within your design ( myDesign.vue ), trigger an event once your data is loaded

this.$root.$emit('design_completed', true);

Next, make sure to listen for the event in your page ( myPage.vue )

mounted(){
    this.$root.$on('design_completed', (status) => {
        // Retrieve user information from the Vuex store
    });
}

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

What is the best way to fill in fields on my webpage using a dropdown menu choice?

I'm exploring the world of ASP.NET MVC, AJAX, and jQuery for the first time. I'm attempting to populate some text boxes on my website based on a dropdown selection but it seems like the data isn't getting through. I suspect that the 'ch ...

Troubleshooting a scenario where making edits to a mongoDB item does not result in any updates

I am struggling with a problem in my nodeJS application involving updating items in a mongoDB database. I have successfully implemented features to add and remove notes, but when attempting to update a note, the changes do not reflect in the database. Desp ...

Vuex has reserved this keyword

I am working on a Laravel application with the following code in app.js: require('./bootstrap'); window.Vue = require('vue'); import { store } from './store/store' import Sidebar from './Sidebar' Vue.component(& ...

A tutorial on creating circular patterns within a pyramid structure using p5.js and matter.js

I've been attempting to create a pyramid shape using multiple circles, similar to this: balls in pyramid shape To achieve this, I've developed a 'Balls' class: class Balls { constructor(x, y, radius, color, ballCount) { this.x = ...

Is there a way to eliminate a specific input box using the jquery remove function?

I've been working on some code and have run into an issue. Currently, the remove function only works on one input box that is created with the append function. I would like it to be able to work on every input box generated through the append function ...

To enhance user experience, consider incorporating a 'Next Page' feature after the completion of every four paragraphs,

Here is a code snippet that can be used to print 'n' number of paragraphs: <% while(rs.next()){ String para=rs.getString("poems"); %> <p> <%=para%> </p> <!-- n number of p tags are printe ...

unable to display items in the navigation bar according to the requirements

Currently, I am in the process of developing an application using reactjs and material-ui. This particular project involves creating a dashboard. In the past, I utilized react-mdl for components and found it to work well, especially with the navbar compone ...

Unlocking the Power of Vue 3 Composition API for Section Rebuilding

In my project, there is a file named CreateSales.vue which is incorporated in Layout.vue. In CreateSales.vue, a specific code snippet loads when the file is executed, shown below: <FormModal v-if="processingData" :processingData="processi ...

Vue CLI-generated project experiencing issues with embedding Font Awesome code

After setting up a Vue project using the Vue CLI, I received an embed code for Font Awesome 5 in my email. I proceeded to insert this code into the index.html file located in the public folder of my project. <head> <script src="https://use.font ...

asp.net website fully compressed using GZip

I am currently developing a Single Page Application (SPA) and I have encountered an issue with the size of my JavaScript files, which are about 300 KB. Additionally, the web services (.asmx files) that generate jsdebug files add another 350 KB to the bundl ...

Utilize Jquery to transform 3 arrays into separate objects distinguished by unique IDs

Recently, I've been experimenting with a very simplistic jquery admin area menu. My goal is to have jQuery create 3 identical menus with different IDs. I was able to accomplish this by creating a function and calling it three times with various variab ...

Tips for sending Json data through a form to a controller and storing it in a database

I am working on a form that contains a sample table with values. The table (id=sampleTbl) has two columns: name and age. My goal is to save this data into my database table named person (id=AI, name, age) when the submitButton (id=idOfButton) is clicked. ...

A more efficient method for creating a nested array of distinct values using JavaScript

The scenario: My website has a complex html table structure to showcase hierarchical data, with the ability for users to toggle visibility of individual rows. Each row is identified by a dom id consisting of a level number and primary key specific to that ...

Right-align SELECT-OPTIONS text

Here are the screenshots of the form I'm currently working on. I am aiming to create a select box in the form where the text within the options is aligned to the right. After an option is selected, the chosen text should be displayed as illustrated i ...

Implementing dynamic title rendering based on image in vue.js

This is the code I'm working with, aiming to display slider data. My goal is that if image[0] appears on the slider, it should return title [0]. I'm quite curious about what could be missing in my setup.code-image ...

How can we fetch data from the server in Vue 2.0 before the component is actually mounted?

Can anyone help me with this question noted in the title? How can I prevent a component from mounting in <router-view> until it receives data from the server, or how can I fetch the data before the component is mounted in <router-view>? Here a ...

Is the process.env variable used universally for environmental variables, or is it specifically designed for use in Node.js

Can process.env function as a universal environment variable or is it exclusive to NodeJs? https://nodejs.org/dist/latest-v8.x/docs/api/process.html#process_process_env Instructions on setting it using the node command are provided: $ node -e 'proc ...

Acquire a Vue component on a separate page by clicking a button on another Vue component or an HTML button click

Is there a way to dynamically load a Vue component on a different page when an HTML button is clicked? -HTML button <a class="contentButton ml-n5" id="addCategoryPrice">Add Price<i class="fa fa-plus-circle"></i ...

Issues with rendering in Next.jsORErrors encountered during rendering

Encountering errors while attempting to build my page using "Yarn Build" Automatically optimizing pages ... Error occurred prerendering page "/design/des". More details: https://err.sh/next.js/prerender-error: Error: Cannot find module './des.md&apos ...

Using Typescript to remove an element from an array inside another array

I've encountered an issue while trying to remove a specific item from a nested array of items within another array. Below is the code snippet: removeFromOldFeatureGroup() { for( let i= this.featureGroups.length-1; i>=0; i--) { if( this.featureGr ...