Skip to content

Instantly share code, notes, and snippets.

@Kelin2025
Last active August 14, 2017 14:21
Show Gist options
  • Save Kelin2025/cf66f10717eaf9cbccff0aca98c8fb95 to your computer and use it in GitHub Desktop.
Save Kelin2025/cf66f10717eaf9cbccff0aca98c8fb95 to your computer and use it in GitHub Desktop.
Vue-apicase example
<template>
<div>
<div v-if="apis.hello.pending">Loading</div>
<div v-else>
<button @click="$api.go('hello')">Hello</button>
</div>
</div>
</template>
<script>
// Vue.use(VueApicase, new Container(...))
// P.S. Container with hello service
export default {
data: () => ({
text: 'Click to start'
}),
// Options object for api hooks
api: {
hello: {
hooks: {
before (ctx, next) {
// Component instance
console.log(ctx.vm)
// Store
console.log(ctx.store)
// Router instance
console.log(ctx.router)
// Route object
console.log(ctx.route)
ctx.vm.text = 'Before hook called'
next()
},
success (ctx) {
ctx.vm.text = 'Success hook called'
},
error (ctx) {
ctx.vm.text = 'Error hook called'
},
finished (ctx) {
setTimeout(() => {
ctx.vm.text = 'Finished with 1s delay'
}, 1000)
},
aborted (ctx, reason) {
ctx.vm.text = 'Aborted hook called'
}
}
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment