How does the vue single-page application manage global events?

now need to do a project to run on a button phone (yes, similar to PHS, but the system is KaiOS), project has multiple routes, many basic components, each component needs to register window.onkeydown events, I now copy and paste each component to re-register, and then remove the keydown event in the beforeRouteLeave hook. And public components such as dialog, actionsheet and other common components also register window.onkeydown events.

would like to consult the senior front-end er, how to manage this kind of problem? And buttons often conflict, because in the case of different components, the events triggered by the left, middle and right buttons at the bottom of the phone"s interface are still different, so it is necessary to add a lot of conditions to judge

.

related codes

activated () {

window.addEventListener("keydown", this.onkeyHandle);

},
beforeRouteLeave (to, from, next) {

console.log("session list router leave");
window.removeEventListener("keydown", this.onkeyHandle);
next();

},
onkeyHandle (evt) {

let key = evt.key;
switch (key) {
    case "ArrowUp":
        //TODO
        break;
    case "ArrowDown":
        //TODO
        break;
    case "Enter":
        //TODO
        break;
    case "SoftRight":
        //TODO
        break;
    case "SoftLeft":
        // TODO
        break;
    case "Backspace":
        //TODO
        break;
    default:
        console.log("default");
}

}

Dec.25,2021

Button phone + KaiOS system = brain pain


write a global instruction and do it in rxjs's way of thinking.

bindsubscribe
updateunsubscribe
unbindunsubscribe

modifiers can be used to disable other keys and specify keys and so on.

<div v-globalkey.softleft="***"></div>
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb3992-46eea.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb3992-46eea.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?