Can I react to an event in a vue template? Say a child component dispatches an event $dispatch('userAdded'), could I do something like this in the parent component:
<div class="alert alert-info" v-if="userAdded"> User was created! </div> or, if not, can I access variables of the child component?
<div class="alert alert-info" v-if="$refs.addView.form.successful"> User was created! </div> I tried both without success.
Also, while I'm here, is there an expressive way to hide elements after a certain amount of time? Something like (to hide after 2s):
<div class="alert alert-info" v-if="$refs.addView.form.successful" hide-after="2000"> User was created! </div> Thanks!
edit: wrote my own hide-after directive:
Vue.directive('hide-after', { update: function(value) { setTimeout(() => this.el.remove(), value); } }); <div class="alert alert-info" v-hide-after="2000"> This will be shown for 2 seconds </div>
form.successfulpart of the data, props or a computed in youraddViewcomponent?form.successfulis part of my data in theaddViewcomponentdata? That's what I'm trying to avoid if there's an easier way.dataor create it withthis.$seton the fly