Skip to content

Instantly share code, notes, and snippets.

@bas080
Created August 30, 2022 09:22
Show Gist options
  • Save bas080/4b6bb2233700f6cde94d28c0cb46a0f9 to your computer and use it in GitHub Desktop.
Save bas080/4b6bb2233700f6cde94d28c0cb46a0f9 to your computer and use it in GitHub Desktop.
<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