Estoy intentando borrar un setTimer() cada vez que se presiona una tecla en mi cuadro de entrada de texto, ya que mi entrada de texto sigue enviando solicitudes de actualización a mitad de la escritura, lo que causa problemas. Sin embargo, el código que tengo para abordar este problema no funciona, debido a la ubicación de mi 'let'; sin embargo, lo puse en todos los lugares que se me ocurrieron, o cambié a 'Var' y aún no funciona. Agradecería la información sobre cómo puedo modificar esto para lograr el resultado deseado.
JS:
computed: { ...mapGetters(['allDocumentTypeGroups', 'currentTicketCaseFiles', 'activeAttachmentIndex', 'showAttachmentsPreview', 'activeAttachments']), attachmentAcceptedLabel() { return this.attachmentAccepted ? this.t('accepted') : this.t('ignored'); }, attachmentAccepted: { get: function () { return !this.attachment.ignoreAttachment; }, set: function (val) { return this.updateAttachment([this.attachment.id, { ignoreAttachment: !val }]); }, }, documentType: { get: function() { return this.attachment.documentTypeId; }, set: function(val) { return this.updateAttachment([this.attachment.id, { documentTypeId: val }]); }, }, approveAttachment: { get: function() { return this.attachment.approvedAttachment; }, set: function(val) { return this.updateAttachment([this.attachment.id, { approvedAttachment: val }]); }, }, strValue: { let timer; get: function () { return this.attachment.strValue; }, set: function (val) { if(timer){ clearTimeout(timer); } let self = this; timer = setTimeout(function(){ return self.updateAttachment([self.attachment.id, { strValue: val }]) },8000); }, }, },No puede poner variables en un objeto literal, use una propiedad.
strValue: { timer: null, get: function () { return this.attachment.strValue; }, set: function (val) { if(this.timer){ clearTimeout(this.timer); } let self = this; this.timer = setTimeout(function(){ return self.updateAttachment([self.attachment.id, { strValue: val }]) },8000); }, },