Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop my vue component from rendering until a call completes

I've googled this but I can't find any specific solution. Basically I have a vue component that depends on an init call and I want it to stop rendering until the call completes, at which point I want the component to render. Seems simple but unless I'm missing something I can't find any lifecycle method that does that.

like image 243
whatoncewaslost Avatar asked May 29 '18 14:05

whatoncewaslost


People also ask

How do I turn off Vue components?

Vue Button component can be enabled/disabled by giving disabled property. To disable Vue Button component, the disabled property can be set as true .

What is conditional rendering in Vue?

Conditional rendering refers to the ability to render distinct user interface (UI) markup based on whether a condition is true or not. This notion is frequently used in contexts like showing or hiding components (toggling), switching application functionality, handling authentication and authorization, and many more.

Can a component call itself Vue?

Recursion and Vue Components In Vue, recursion is very much possible and quite useful. I mean, not only in Vue, we can follow the rules above to implement recursive behavior in any framework. So, based on the given definition, we can say that a recursive component is a component invoking itself.


1 Answers

You can use v-if for that purpose

<template>
    <div v-if="loaded"></div>
</template>

<script>
    export default {
        name: 'TestComponent',
        data: function () {
            return {
                loaded: false
            }
        },
        created() {
          callExternalServices().then(() => {
             this.loaded = true
          })
        }
    }
</script>

It will render an empty component until loaded == true

like image 153
ittus Avatar answered Oct 21 '22 05:10

ittus