I'm trying to implement a slack like feature to send a message only when pressing exact enter (without shift pressed)
Considering 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 impact
this.$socket.emit('message', { text: this.message });
console.log(this.message); // Print the message with another '\n' at the end due to textarea default behavior
}
}
}
Does anyone has an idea of how I can avoid having the last '\n' without using a regex to delete it before sending it to the backend (which I think will be dirty) ?
Thank you
PS : I'm pretty new to VueJS stack and hope that my question is not obvious
EDIT: This question is similar but the proposed solution is not working