Created
August 30, 2022 09:22
-
-
Save bas080/4b6bb2233700f6cde94d28c0cb46a0f9 to your computer and use it in GitHub Desktop.
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> | |
<slot v-scope="api" /> | |
</template> | |
<script> | |
export default { | |
props: { | |
data: Function | |
}, | |
data: () => ({ | |
data: null, | |
loading: true, | |
failed: false, | |
error: null, | |
}), | |
watch: { | |
data() { | |
this.retry() | |
} | |
}, | |
created() { | |
this.retry() | |
}, | |
methods: { | |
retry() { | |
this.loading = true | |
try { | |
this.data = await this.data() | |
this.failed = false | |
} catch (err) { | |
this.error = err | |
this.failed = true | |
} | |
this.loading = false | |
} | |
}, | |
computed: { | |
api() { | |
return { | |
retry: this.retry.bind(this), | |
failed: this.failed, | |
loading: this.loading, | |
data: this.data | |
} | |
}, | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment