From 0f362e78cbaf8c4e99ab4392c061290a89369573 Mon Sep 17 00:00:00 2001 From: cagataycivici Date: Mon, 16 Mar 2020 17:22:48 +0300 Subject: [PATCH] Unbind on destroy --- src/components/terminal/Terminal.vue | 29 +++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/components/terminal/Terminal.vue b/src/components/terminal/Terminal.vue index 54b16ac83..552bc5213 100644 --- a/src/components/terminal/Terminal.vue +++ b/src/components/terminal/Terminal.vue @@ -19,19 +19,6 @@ import TerminalService from './TerminalService'; export default { - data() { - return { - commandText: null, - commands: [] - } - }, - mounted () { - TerminalService.$on('response', (response) => { - this.commands[this.commands.length - 1].response = response; - }); - - this.$refs.input.focus(); - }, props: { welcomeMessage: { type: String, @@ -42,6 +29,19 @@ export default { default: null } }, + data() { + return { + commandText: null, + commands: [] + } + }, + mounted() { + TerminalService.$on('response', this.responseListener); + this.$refs.input.focus(); + }, + beforeDestroy() { + TerminalService.$off('response', this.responseListener); + }, methods: { onClick() { this.$refs.input.focus(); @@ -52,6 +52,9 @@ export default { TerminalService.$emit('command', this.commandText); this.commandText = ''; } + }, + responseListener(response) { + this.commands[this.commands.length - 1].response = response; } } }