I've been trying to figure this out for hours and I'm not sure what's wrong with my vue custom events.
<!-- part of the vue template: the main element -->
<!-- not working <button @click='$emit(\"open-modal-zone\")'></button> -->
<!-- not working <button @click='activateFilterModalViaEmit'></button> -->
<modal-zone :filter-obj='filterObj' @open-modal-zone='modalActive=true' @close-modal-zone='modalActive=false' v-if='modalActive' ></modal-zone>
<!-- the component in question -->
Vue.component('modal-zone', {
props : ["filterObj", "modalActive"],
template: "<div id='modal-zone'>" +
"<p @click='$emit(\"close-modal-zone\")'>Close</p>" +
"<filter-modal-dialog-controls :filter-obj='filterObj'></filter-modal-dialog-controls>" +
"</div>"
});
<!-- filter-dialog-controls component omitted (I haven't gotten that far yet) -->
// the vue js of my app
var v = new Vue({
el : "#editing-div",
data : {
modalActive : false,
filterObj : {
filterModalActive : false
}
},
methods : {
activateFilterModalViaEmit : function(){
this.$emit("open-modal-zone"); //why doesn't this work?
}
activateFilterModal : function(){
this.modalActive = true; // this works.. but I want $emit!
}
}
});
The problem is that while I'm able to emit a close event from inside the component area, (the @click on the
element), I can't do so from my main vue object's methods, and neither can I do it by sticking this.$emit("open-modal-zone")
it into the button which I'd like to use to open this modal component.
So there you have it, I would like to intuitively do my events through the $emit
functions, but what can I do to make my open function actually work in this case?