Implement a loading spinner in VueJs and Laravel to display in front of the page during the data loading process

I have implemented a loading spinner in my Vue project to display until the data is fully loaded. I created a separate component called LoadingComponent.vue for this purpose.

<template>
    <div class="preloader" v-if="show">
        <div class="spinner-border" style="width: 3rem; height: 3rem;" role="status">
            <span class="visually-hidden">Loading...</span>
        </div>
    </div>
</template>

<script>
export default {
    name: "PreloaderComponent",
    data: () => ({
        show: true
    }),
    mounted(){
        if(Boolean(this.show)) this.showToggle()
    },
    methods: {
        showToggle(){
            setTimeout(() => {
                this.show = false
            }, 1000)
        }
    }
}
</script>

<style lang="scss">
.preloader {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    z-index: 1050;
    background: rgba(0, 0, 0, .3);
    display: flex;
    align-items: center;
    justify-content: center;
}
</style>

To integrate the LoadingComponent with Dashboard.vue and make the spinner disappear once all widgets are loaded, some additional modifications are required. The current implementation does not hide the spinner after all widgets are loaded.

In order to address this issue and enhance the user experience, I am exploring solutions to automatically add a black spinner and slightly dim the background while the dashboard data is loading, which should continue working seamlessly even as new API calls are added in the future.

I am seeking a solution that ensures the loading spinner remains visible on the dashboard until all page content is successfully loaded. It should be optimized to handle cases where data retrieval from the API may take longer than expected or when the data loads quickly, preventing users from waiting unnecessarily.

Answer №1

Check out this unique SVG loader code:

<svg xmlns="http://www.w3.org/2000/svg" width="44" height="44" viewBox="0 0 44 44">
    <style type="text/css">
          <![CDATA[
            g circle {
              stroke: #fff;
              stroke-width: 3;
            }
            g circle {
              opacity: 0;
              animation: size cubic-bezier(0.165, 0.84, 0.44, 1) 1.8s infinite,
                         opacity cubic-bezier(0.3, 0.61, 0.355, 1) 1.8s infinite;
              transform-origin: 50% 50%;
            }
            g circle:last-child { animation-delay: 0.9s; }
            @keyframes size {
              0% { transform: scale(0); }
              100% { transform: scale(1); }
            }
            @keyframes opacity {
              5% { opacity: 1; }
              100% { opacity: 0; }
            }
          ]]>
    </style>
    <g fill="none">
        <circle cx="22" cy="22" r="20"/>
        <circle cx="22" cy="22" r="20"/>
    </g>
</svg>

This SVG loader is versatile and works without the need for additional JS or Vue frameworks. There are many other options available online as well.

These loaders load quickly and are great for adding to your website. You can place the loader outside of the main content area so you can control when it disappears, especially if your app has a longer loading time.

To integrate this loader effectively, consider using a black or white background and centering it on your webpage with absolute positioning.

You can find this loader and more designs at

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

Having trouble with setting up elasticdump: encountering an unexpected identifier error in the async _loop

When installing elasticdump, a series of warnings are displayed like this $ npm install -g elasticdump npm WARN deprecated <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="255740545040565165170b1d1d0b17">[email protected] ...

What is the method for showing a value as a decimal in a vuejs input field?

I am encountering an issue where, in a VueJS input field, the decimal places are being stripped from the number 2000.00 that I am trying to display. <div id="app"> <input class="form-control" type="number" ...

Display or conceal HTML content based on the input's property type

Looking to toggle the visibility of an icon on my input based on the prop type. If the type is set to password, the icon will be displayed for toggling between visible and hidden password; if the type is not password, the icon should be hidden by setting ...

Issue with the node.js Express generator app failing to respond at the moment

I have only made changes to the main app.js file after installing express generator and npm install. I am inexperienced, so it's possible there is a typo in the app.js file. Here is the file and console output. Thank you for your help. When I try to a ...

What is the best way to obtain logs from a NodeJs application that is being run in forever npm

Is there a way for me to view the logs of my nodejs server after using forever start server.js? I want to see what is being logged, check for any live errors, and more. I searched through their documentation but couldn't find anything helpful. I need ...

Error: ionic serve is unable to locate the 'reflect-metadata' module

I am new to Ionic2 and following the steps: $ npm install -g ionic cordova $ ionic start cutePuppyPics --v2 $ cd cutePuppyPics $ ionic serve However, I encountered an error: "Cannot find module 'reflect-metadata' $ ionic info Cordova CLI: 6.5 ...

Retrieve the v-id-xx attribute value for scoped styling in a Vue Single File Component

When using pure JavaScript to add elements in a Vue Single File Component, the added elements are missing the v-id-xx attribute for scoped CSS. Is there a way to retrieve the component's v-id-hash value using only JavaScript? ...

Developing Laravel Blade shortcuts similar to those found in Wordpress

I am currently facing a challenge with a mail template in Laravel blade that needs to be dynamic and saved in the database. Below is an example of the registration_complete.blade.php file: <html> <body> {{$dynamic_content ...

Error message on WordPress or NPM: the JavaScript file for Bootstrap cannot run without jQuery loaded first

Currently, I am using NPM to bundle bootstrap along with several other scripts for a Wordpress theme. Since WordPress already loads jquery by default, I have made sure to exclude jquery from the bundle. However, even though I can see in Google Dev Tools t ...

foreverjs neglects to log the child process's console.log output to any log files

I currently have a nodejs server running that fetches data using the setInterval function every x seconds. Here is a snippet of that part of the app: startPolling () { debug('Snmp poller started'); timers.setInterval( this.poll( ...

Designing personalized plugins with Typescript in Nuxt

In my Nuxt project, I have implemented a custom plugin file that contains an object with settings called /helpers/settings: export const settings = { baseURL: 'https://my-site.com', ... }; This file is then imported and registered in /plugi ...

"The webpack-dev-server seems to be failing to forward requests to an external domain using the proxy

I'm currently facing an issue with setting up the webpack-dev-server proxy configuration to route api requests to an external domain. Despite my efforts, I am unable to get it to function properly. Below is my configuration: var path = require(&apos ...

Utilizing Nicknames in a JavaScript Function

I'm dealing with a function that is responsible for constructing URLs using relative paths like ../../assets/images/content/recipe/. My goal is to replace the ../../assets/images section with a Vite alias, but I'm facing some challenges. Let me ...

Switching XML to JSON using React.js

Currently, I am in the process of developing an application with a requirement to retrieve data from a web API that provides XML responses. However, my objective is to obtain this information in JSON format, but unfortunately, the API does not offer suppor ...

`Developing reusable TypeScript code for both Node.js and Vue.js`

I'm struggling to figure out the solution for my current setup. Here are the details: Node.js 16.1.x Vue.js 3.x TypeScript 4.2.4 This is how my directory structure looks: Root (Node.js server) shared MySharedFile.ts ui (Vue.js code) MySharedFi ...

Struggling to connect executable 'node' - encountering an npm error while running in Termux

Having trouble linking executable "node" due to inability to locate symbol "__emutls_get_address" that is referenced by "/data/data/com.termux/files/usr/bin/node"... Any suggestions on how to resolve this issue? ...

Tips on recycling JavaScript files for a node.js API

I'm currently using a collection of JS files for a node.js server-side API. Here are the files: CommonHandler.js Lib1.js Lib2.js Lib3.js Now, I want to reuse these JS files within an ASP.NET application. What's the best way to bundle these f ...

Troubleshooting problems during Vue setup

Just diving into Vue development and hitting a roadblock. Here's what I've done so far: I followed the installation guide on the Vue 3 documentation, which can be found at the following link: https://v3.vuejs.org/guide/installation.html#npm I ...

Set up Express.js using npm

Just set up nodejs on my Ubuntu 14.04 system. Upon running node --version, I see that it's v4.4.2. Also, npm is installed with version 3.9.2. When I execute the command npm install -g express, this is the output I get: install express js Once the ins ...

React is up and running smoothly on my local machine, but unfortunately encountering issues on Vercel

I have encountered an issue while trying to deploy my website on Vercel. Despite the build logs showing a successful compilation, I am receiving a "failed to compile" error: [16:43:24.951] Running build in Washington, D.C., USA (East) – iad1 [16:43:25.05 ...