1

I want to setup a Loading screen on App loading. I am currently using a Loading component and setting up its time interval to 2 seconds. However, that is not the proper way to set up a Loading screen. What is the best way to handle the loading state for the entire app?

I have directly used the Loading component in the router-view of the App.vue, so I do not have to use the Loading component in each and every component of the App.

The following is my App.vue



<template>
  <v-app class="container">
    <v-app-bar color="green" class="app-bar">
      <v-toolbar-title class="ml-0 pl-4">
        <span class="hidden-sm-and-down">{{ appName }}</span>
      </v-toolbar-title>
      <v-btn rounded depressed dark large @click="gotoHome()">
        <h3>Dashboard</h3>
        <v-icon class="px-2">mdi-ballot</v-icon>
      </v-btn>
      <v-btn rounded depressed dark large @click="dialog = !dialog">
        <h3>Markets</h3>
        <v-icon class="px-2">mdi-apps</v-icon>
      </v-btn>
      <v-btn rounded depressed dark large @click="gotoSettings()">
        <h3>Settings</h3>
        <v-icon class="px-2">settings</v-icon>
      </v-btn>
      <v-btn rounded depressed dark large @click="gotoVerus()">
        <h3>Verus</h3>
        <v-icon class="px-2">mdi-apps</v-icon>
      </v-btn>
    </v-app-bar>
    <v-dialog v-model="dialog" fullscreen hide-overlay transition="dialog-bottom-transition">
      <v-card>
        <v-toolbar>
          <v-btn dark @click="dialog = false">
            <v-icon>mdi-close</v-icon>
          </v-btn>
          <v-toolbar-title>Markets</v-toolbar-title>
          <div class="flex-grow-1"></div>
          <v-toolbar-items>
            <v-btn dark text @click="dialog = false">back</v-btn>
          </v-toolbar-items>
        </v-toolbar>
        <v-list three-line subheader>
          <v-subheader>Go to markets</v-subheader>
          <v-list-item>
            <v-list-item-content>
              <v-list-item-title>Informational Section</v-list-item-title>
              <v-list-item-subtitle>Please wait for the available market links to load</v-list-item-subtitle>
              <AppMarkets v-on:gotoMarket="gotoMarket" :key="componentKey" />
            </v-list-item-content>
          </v-list-item>
        </v-list>
      </v-card>
    </v-dialog>
    <v-navigation-drawer
        v-model="drawer"
        location="left"
        temporary
      >
        <v-list
          :items="items"
        ></v-list>
      </v-navigation-drawer>
      <Loading v-if="loading"></Loading>
      <router-view v-else>
      </router-view>
  </v-app>
</template>


<script>
import AppMarkets from './views/AppMarkets.vue'
import {ref, onMounted} from 'vue'
import Loading from './Loading.vue'


export default {
  name: 'App',
  components: {
    AppMarkets,
    Loading
},
  props: {
    source: String
  },
  setup() {
    const loading = ref(true);
    onMounted(() => {
      // For demonstration purposes, setting loading to true for 2 seconds.
      setTimeout(() => {
        loading.value = false;
      }, 2000);
  });
    return {
      loading,
    };
  },

  methods: {
    gotoHome() {
      this.$router.push('/')
    },
    gotoSettings() {
      this.$router.push('/settings')
    },
    gotoVerus() {
      this.$router.push('/verus')
    },
    gotoMarket: function(base, rel) {
      console.log("Going to new market..." + base + "/")// + rel)
      console.log(this.componentKey)
      this.componentKey += 1
      this.dialog = !this.dialog
      window.location.href='/traderview/'+base+'/'+rel;
    },
    doAction: function(command) {
      window.location.href = "/" + command.toLowerCase().replace(/ /g, "");
    }
  },
  data: () => ({
    appName: 'OrderBook Live',
    base: '',  
    componentKey: ref(0),
    dialog: ref(false),
    drawer: ref(false),
  }),
  
  
}
</script>
5
  • 1
    loading screens are usually tied to async operations/network requests, i.e. set the loading screen = true before the operation, then false after. the question is a bit vague and it's not clear what your actual use case is to provide a definite answer. Commented Jan 3, 2024 at 14:58
  • Updated my question hope now I would get some help Commented Jan 4, 2024 at 5:50
  • You didn't really add any important information to the question. What loading tasks are you talking about? There's no async tasks that I see in your code. You say you have timeout right now to show the loading screen for 2 seconds. What in those 2 seconds is your app "loading" (files, network requests, something else) that you need the loading screen for? Be specific. If you can't name anything specific, then maybe you don't actually need a loading screen. Commented Jan 4, 2024 at 14:44
  • On components loading simple Commented Jan 5, 2024 at 18:45
  • From everything communicated so far it seems like you're looking for a reason to use a loading screen without having an actual need. Commented Jan 5, 2024 at 19:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.