Answer the question
In order to leave comments, you need to log in
How to make in textarea so that when ctrl + enter is pressed, it will wrap to a new line, enter will send a message to vue?
The essence of the problem is this, when you press enter, it transfers by default puts a line break, then performs some actions, I need to block the default transfer.
Here is an example code:
<textarea
type="text"
v-model="text"
@keyup.enter.prevent="sendMessage"
@keyup.ctrl.enter.prevent="newLine"
></textarea>
data() {
return {
text: ""
}
},
methods: {
sendMessage() {
this.$emit("keyupCtrlEnter");
},
newLine(e) {
let caret = e.target.selectionStart;
e.target.setRangeText("\n", caret, caret, "end");
this.text = e.target.value;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question