<div id="app">
<component :is="currentForm" v-on:form="switchForm"></component>
</div>
<template id="login-template">
<div>
<h1>Login form</h1>
<form>
<label>Email</label>
<input v-model="email">
<label>Password</label>
<input v-model="password">
</form>
<a href="#" @click="callSwitchForm('registration')">Registration</a>
</div>
</template>
<template id="registration-template">
<div>
<h1>Registration form</h1>
<form>
<label>Email</label>
<input v-model="email">
<label>Password</label>
<input v-model="password">
<label>Re-enter password</label>
<input v-model="repassword">
</form>
<a href="#" @click="callSwitchForm('login')">Login</a>
</div>
</template>
Vue.component('login', {
template: '#login-template',
data: function () {
return {
email: '',
password: '',
}
},
methods: {
callSwitchForm: function(form) {
this.$emit('form', form)
}
}
})
Vue.component('registration', {
template: '#registration-template',
data: function () {
return {
email: '',
password: '',
repassword: '',
}
},
methods: {
callSwitchForm: function(form) {
this.$emit('form', form)
}
}
})
var app = new Vue({
el: '#app',
data: {
currentForm: 'login'
},
methods: {
switchForm: function(form) {
this.currentForm = form
}
}
})