i have a component register and add event @submit.prevent inside the template by $emit , i tried to console.log on the inisde method component, it was works, but when on my main js, it does not work and nothing, but not error
this is my component example :
Vue.component("register", {
props: {
form: Object
},
template: `
<div class="container">
<div class="row">
<div class="col-sm-4 offset-4">
<form @submit.prevent="goRegister">
<div class="form-group">
<label for="username">username</label>
<input type="text" class="form-control" id="usernameRegister" aria-describedby="emailHelp" placeholder="Enter username" v-model.trim="form.username" required>
</form>
</div>
</div>
</div>
`,
methods: {
goRegister() {
this.$emit("doRegister", this.form);
}
}
});
this is my parent on my html :
<register v-on:do-register="handleRegister" :form="forms"> </register>
and on my vue main js
new Vue({
data:{
forms: {
username: null,
email: null,
password: null,
name: null,
age: null
}
},
methods : {
handleRegister() {
console.log(this.forms.username);
}
}
})
i tried to console that method handleRegister, but nothing happened and not error, is that something missing on my parent component ??