[Vuejs]-Vue 3 check if emit is present

-2๐Ÿ‘

I came up with this solution.

if (emit.listener.addToCart && props.product.id === data.id) {
  emit('onBeforeAdd')
} else if (emit.listener.changeQuantity && props.product.id === data.id) {
  emit('onBeforeAdd')
} else {
  emit.listener.setModal({ name: 'modal', id: props.product.id })
}

As you can see, you can handle the cases in a separate ways, not only by the event name, but also by conditions.

Leave a comment