<template> <div class="page"> <section class="form inputs"> <h3>Login</h3> <label>Email</label> <input v-model="email" required> <label>Password</label> <input v-model="password" type="password" required> <button @click="login">Login</button> <div class="error"> {{error}} </div> </section> </div> </template> <script> function login() { this.error = "" return fetch(`/api/login`, {method: 'POST', body: JSON.stringify( {email: this.email, password: this.password} ), }).then(response => { if (response.ok) { this.$emit('login') window.location.hash = '' } else { this.error = "Invalid credentials" } }) } export default { emits: [ 'login' ], methods: { login }, data() { return { email: "", password: "", error: ""} }, } </script>