Answer the question
In order to leave comments, you need to log in
Why can't input be cleared after socket.io event?
send: function (e) {
e.preventDefault();
let chatMsg = $('#chat_message');
socket.emit('new_message', {message: chatMsg.val()}); // без этой строчки очистит инпут
chatMsg .val('');
},
<form action="" @submit="send" v-if="authCheck()">
<input id="chat_message" autocomplete="off"/>
<button type="submit">Send</button>
</form>
/**
* Defer a task to execute it asynchronously.
*/
var nextTick = (function () {
var callbacks = [];
var pending = false;
var timerFunc;
function nextTickHandler () {
pending = false;
var copies = callbacks.slice(0);
callbacks.length = 0;
// тут вернет значение обратно в инпут
for (var i = 0; i < copies.length; i++) {
copies[i]();
}
}
// the nextTick behavior leverages the microtask queue, which can be accessed
// via either native Promise.then or MutationObserver.
// MutationObserver has wider support, however it is seriously bugged in
// UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It
// completely stops working after triggering a few times... so, if native
// Promise is available, we will use it:
/* istanbul ignore if */
clearChatMsg: function(){
$('#chat_message').val('');
},
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