Click Enter on the vue login page to log in

Write a submit button on the login page to log in, and click Enter to call the login method

<el-button type="primary" @click="onLogin">提交</el-button>

Script write login method and click Enter method

methods: {

        onLogin() {

                this.$router.push('/home');

                },

        keyDown(e){

                e = window.event

                if(e.keydown || e.code == 'Enter'){

                        this.onLogin()

                }

        }

      },

Need to write a listening event to listen to the carriage return event

mounted(){

        window.addEventListener('keydown',this.keyDown)

},

destroyed(){

        window.removeEventListener('keydown',this.keyDown)

}

Guess you like

Origin blog.csdn.net/qq_36536195/article/details/128093929