Unbind on destroy

pull/256/head
cagataycivici 2020-03-16 17:22:48 +03:00
parent 33f0533a78
commit 0f362e78cb
1 changed files with 16 additions and 13 deletions

View File

@ -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;
}
}
}