Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Setting Up a Vue 3 Project with Vite and Implementing a Loading Screen

Tech 2

Project Initialization with Vite

Prerequisites

  • Node.js version 16.14.2
  • pnpm version 8.15.4

Creating the Project

To install pnpm globally, use:

npm install -g pnpm

Initialize a new Vite project by running:

pnpm create vite

During setup, specify:

  • Project name: e.g., ruoyi-ui
  • Framework: Select Vue
  • Variant: Choose JavaScript

Running the Project

Navigate to the project directory and install dependencies:

pnpm install

Start the development server:

pnpm run dev

The applicasion will be accessible at http://127.0.0.1:5173/.

Project Structure Cleanup

  • Remove HelloWorld.vue from src/components/
  • Delete vue.svg from src/assets/
  • Remove style.css from src/
  • Update App.vue in src/ with:
<script setup>
</script>

<template>
  <div>hello vite</div>
</template>

<style scoped>
</style>
  • Modify main.js in src/ to:
import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')

Loading Screen Implementation

CSS Styling

Add the following CSS to style the loading screen:

html, body, #app {
  height: 100%;
  margin: 0;
  padding: 0;
}

#loader-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 999999;
  background-color: #7171C6;
}

#loader {
  display: block;
  position: relative;
  left: 50%;
  top: 50%;
  width: 150px;
  height: 150px;
  margin: -75px 0 0 -75px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: #FFF;
  animation: rotate 2s linear infinite;
  z-index: 1001;
}

#loader::before {
  content: "";
  position: absolute;
  top: 5px;
  left: 5px;
  right: 5px;
  bottom: 5px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: #FFF;
  animation: rotate 3s linear infinite;
}

#loader::after {
  content: "";
  position: absolute;
  top: 15px;
  left: 15px;
  right: 15px;
  bottom: 15px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: #FFF;
  animation: rotate 1.5s linear infinite;
}

@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.load_title {
  font-family: 'Open Sans';
  color: #FFF;
  font-size: 19px;
  width: 100%;
  text-align: center;
  position: absolute;
  top: 60%;
  opacity: 1;
  line-height: 30px;
}

HTML Structure

Update the HTML in index.html or a Vue component to include:

<div id="app">
  <div id="loader-wrapper">
    <div id="loader"></div>
    <div class="load_title">Loading system resources, please wait...</div>
  </div>
</div>
<script type="module" src="/src/main.js"></script>

This setup displays a loading animation with a background color and text while the application initializes.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.