When I call the getLogin method within the onSubmit method, I am expecting a code to be returned that I need. However, instead of receiving the expected code, I am getting 0 as output. Can someone help me figure out what I am doing wrong?
<template>
<div class="container">
<h1>Main title</h1>
<form @submit="onSubmit" class="add-form">
<div class="submit-div">
<input type="submit" value="Continue" class="btn" />
</div>
</form>
</div>
<router-view />
</template>
<script>
export default {
name: "Home",
components: {},
data() {
return {
responseCode: 0,
responseData: []
};
},
methods: {
async onSubmit(e) {
e.preventDefault();
this.responseCode = await this.getLogin();
console.log(this.responseCode);
},
async getLogin() {
var requestOptions = {
method: "GET",
redirect: "follow"
};
await fetch("http://localhost:5000/api/twikey/login", requestOptions)
.then(response => response.json())
.then(data => {
return data.Authorization;
})
.catch(error => console.log("error", error));
},
}
};
</script>
<style scoped>
.container {
width: 70%;
height: 500px;
margin: auto;
}
</style>