vue.js中 ,回車鍵實現登錄或者提交表單!


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('密碼錯誤哦,您在好好想想哦');
        }

      })
    },


  },

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM