vue的功能非常強大,但是我們作為一個后端開發人員,前端的東西不一定都弄的很明白,今天就給大家介紹一個回車提交表單的真實案例,達到回車登錄的效果!
@ keyup.enter 實現的效果
<input v-model = "password" type="password" name="" class="pwd" placeholder="密碼" @keyup.enter="handellogin">// 這里是一個輸入框 methods:{ handellogin(){ this.$axios.post(`${this.$settings.Host}/users/login/`,{ username:this.username, password:this.password }).then(response=>{ console.log(response.data); this.$message({ message: '恭喜你,登錄成功了', type: 'success' }); this.$router.push({ path:'/' }) }).catch(error=>{ if (error.response.status === 400) { this.$message.error('密碼錯誤哦,您在好好想想哦'); } }) }, },