javascript - @keyup.enter 仅在选项卡设置为登录按钮时有效
问题描述
我的登录按钮唯一有效的时间是在输入电子邮件和密码后直接点击选项卡按钮时,
我希望它在我按下回车键并且我在登录页面上的任何时候都能正常工作。
这是一个 VueJS 应用程序
html模板
<template>
<div class="login-page" id="login-page">
<div class="form" id="form">
<form class="login-form" id="login-form">
<div class="head-login">
<img class="teamfu-image" src="../assets/teamfu-v.png"/><h2 class="login">Login</h2>
</div>
<hr class="beneathBorder" color="white">
<div>
<p class="text">Email:<input v-model="input.email" class="input" type="text" placeholder='e.g. johndeer@gmail.com'/></p>
<p class="text">Password:<input v-model="input.password" class="input" type="password" placeholder=" " /></p>
</div>
<button type="button" @click="login" @keyup.enter="login" > Login</button>
<p class="message">Not a part of the team? <router-link class="reg" :to="'/register'">Register</router-link></p>
</form>
</div>
</div>
</template>
脚本
<script>
import { checkUser } from "../db/storage";
export default {
name : 'login-page',
data() {
return{
input: {
email: '',
password: ''
}
}
},
methods : {
login() {
if(this.input.email != "" && this.input.password != "") {
if(checkUser(this.input.email, this.input.password) ) {
this.$emit("authenticated", true);
this.$router.replace('/dashboard');
} else {
alert("The username and / or password is incorrect")
console.log("The username and / or password is incorrect");
}
} else {
alert("A username and password must be present")
console.log("A username and password must be present");
}
}
}
}
</script>
解决方案
如果你想要一个页面级的 keyup 处理程序,你需要在你的树上尽可能高地应用它:
<div class="login-page" @keyup.enter="login" id="login-page">
推荐阅读
- javascript - React / Preact 中令人惊讶的缓慢点击事件
- ios - Swift - App Tracking Transparency - 如何显示非个性化 AdMob 内容?
- python - 在 python Numpy 中追加和格式化多维数组
- c# - 试图做一个壁架。问题:transform.position 总是返回vector(0, 0)
- python - 勇敢地不使用 Python Selenium 打开
- docker-compose - 如何在 Dockerfile RUN 中使用环境变量
- javascript - 插入光标js的位置
- azure - 使用 Terraform,如何在 Azure 上创建使用现有托管磁盘的 VM?
- python - 将表单信息导出为 Excel 中的行
- python - 算法问题,如何在python和opencv中找到以角度码为边界的像素数