Skip to content

Instantly share code, notes, and snippets.

@nabrown
Last active March 22, 2020 21:53
Show Gist options
  • Save nabrown/523b10128e02d81c1e29c11c7910cd5b to your computer and use it in GitHub Desktop.
Save nabrown/523b10128e02d81c1e29c11c7910cd5b to your computer and use it in GitHub Desktop.
Using a helper function to test Loading and Error components.
<template>
<div>
<button v-on:click="showChild = !showChild">Toggle Child Component!</button>
<child-component v-if="showChild" message="I am the child component."></child-component>
</div>
</template>
<script>
import LoadingState from '@/components/LoadingState'
import ErrorState from '@/components/ErrorState'
const asyncComponentTester = function(importPromise, latency){
return new Promise((resolve) => {
setTimeout(() => {
resolve(importPromise)
}, latency)
})
}
export default {
name: 'ParentComponent',
components: {
LoadingState,
ErrorState,
ChildComponent: () => ({
component: asyncComponentTester(import('@/components/ChildComponent'), 2000),
loading: LoadingState,
error: ErrorState,
delay: 200,
timeout: 1500
})
},
data(){
return {
showChild: false
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment