简体   繁体   中英

How to convert html,js,css files into SFC using vue?

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;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM