I am trying to convert the html,js,css files into a single file component using Vue. I have defined the form 'logininfo', but an error message appears in the command line saying 'logininfo' is undefined. So I can't check if the login form is working properly. I have defined the 'logininfo' in the form id and when I export it in the script file.
<template>
<div id="login">
<form id="logininfo" method="POST" @submit.prevent="onsubmit">
Email: <input v-model="email" type="email">
Password: <input v-model="password" type="password">
<button v-on:click="login" id="login">Login </button>
</form>
</div>
</template>
<script>
export default {
name: ‘logininfo’,
data() {
email: "",
password: ""
},
methods: {
login: function () {
var account = JSON.parse(localStorage.getItem('userdetails')).find(function(userdetails) {
return (logininfo.email === userdetails.email && logininfo.password === userdetails.password) ? userdetails : null;
});
if(account) {
window.location.href = "index.html?email=" + account.email;
} else {
alert("Email has not been identified. ");
}
}
}}
Since you are referencing the component data inside a nested function, you need to keep a scoped reference to the object.
function () {
var self = this;
var account = JSON.parse(localStorage.getItem('userdetails')).find(function(userdetails) {
return (self.email === userdetails.email && self.password === userdetails.password) ? userdetails : null;
});