I'm attempting to incorporate a slack-like feature that sends a message only when the exact Enter key is pressed (without holding down the Shift key).
Looking at this Vue template
<textarea type="text" v-model="message" @keyup.enter.exact="sendMessage($event)"></textarea>
with this component
export default {
name: 'Typing',
data() {
return {
message: null
}
},
methods: {
sendMessage(e) {
// e.stopPropagation() and e.preventDefault() have no effect
this.$socket.emit('message', { text: this.message });
console.log(this.message); // Prints the message with an extra '\n' at the end due to the default behavior of the textarea
}
}
}
Does anyone have any suggestions on how I can prevent the extra '\n' without resorting to using a regex to remove it before sending it to the backend (which I believe would be messy) ?
Thank you
PS: I'm relatively new to the VueJS framework and I hope that my question is not too basic
EDIT: This question is similar but the proposed solution is not effective