Pattern2 Object(include callback function) instead of Function like a android app callback structure
Object(include callback function)
Function
CallbackChild.vue
<template> <v-btn @click="increment">increment</v-btn> </template> <script lang="ts"> interface OnClickListener { onClick(count: number): (count: number) => {} } export default Vue.extend({ props: { onClickListener: { type: Object, required: true } as PropOptions<OnClickListener> }, data() { return { count: this.obj.initialCount } }, methods: { increment() { this.count++ this.onClickListener.onClick(this.count) } } } </script>
CallbackParent.vue
<template> <CallbackChild :on-click-listener="$data.onClickListener" ></CallbackChild> </template> <script lang="ts"> export default Vue.extend({ data() { const onClickListener = { onClick: (count: number) => { console.log(`onClickListener.onClick(${count})`) } } return { onClickListener } }, } </script>
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Pattern2
Object(include callback function)
instead ofFunction
like a android app callback structure
CallbackChild.vue
CallbackParent.vue