Last active
March 22, 2020 21:53
-
-
Save nabrown/523b10128e02d81c1e29c11c7910cd5b to your computer and use it in GitHub Desktop.
Using a helper function to test Loading and Error components.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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