Bootstrap

vue3 +elementPlus 实现回车Enter登录

1、submit() 为登录事件,@keydown.enter="keyDown()"为用户按下enter键触发的事件

<el-button @click="submit()" @keydown.enter="keyDown()">登录</el-button>

2、keyDown()

//点击回车键登录
const keyDown = (e) => {
	if (e.keyCode == 13 || e.keyCode == 100) {
		submit()
	}
}

3、在onMounted()绑定监听事件

onMounted(() => {
	//绑定监听事件
	window.addEventListener('keydown', keyDown)
});

4.在onUnmounted()绑定销毁事件

onUnmounted(() => {
	//销毁事件
	window.removeEventListener('keydown', keyDown, false)
});

;