When I use an event listener to call a specific function, it behaves strangely. Here is the code snippet:
mounted() {
window.addEventListener("message", this.call); },
methods: {
call(e){
if (e.data === "test"){
this.call2()
}
}
call2(){
console.log("called call2")
}
}
Initially, call2
is called once. However, on subsequent attempts, call2
is called multiple times and the message "called call2" is displayed multiple times in the console. This behavior continues with each try, adding to the number of times call2
is executed in a single action. Is there a solution to prevent this?