vue3enter事件


            <button type="primary"
                    class="logonstyle"
                    @click="submitForm()"
                    @keydown.enter="keyDown()"
            >
                登录
            </button>

onMounted(() => {
  // 绑定监听事件
  window.addEventListener('keydown', keyDown)
})
onUnmounted(() => {
  // 销毁事件
  window.removeEventListener('keydown', keyDown, false)
})
// 点击回车键登录
const keyDown = (e) => {
  if (e.keyCode === 13 || e.keyCode === 100) {
    console.log('触发回车事件')
    submitForm()
  }
}

猜你喜欢

转载自blog.csdn.net/weixin_51263829/article/details/130149671
今日推荐