简体   繁体   English

文本输入的“值”属性不正确

[英]Text input's "value" attribute is incorrect

I have a single input in my Vue app.我的 Vue 应用程序中有一个输入。 It's a part of a component, which is set up like the documentation on the usage of “v-model with components”:它是组件的一部分,其设置类似于“v-model with components”的使用文档

Vue.component('custom-input', {
  props: ['value'],
  template: `
    <input
      v-bind:value="value"
      v-on:input="$emit('input', $event.target.value)"
    >
  `
})

This input is clearly is filled with a value (from Chrome autofill) when the page loads, but in my code I have the following statement:当页面加载时,这个输入显然填充了一个值(来自 Chrome 自动填充),但在我的代码中,我有以下语句:

setInterval(() => { console.log(document.querySelector('input').value); }, 50);

This consistently logs an empty string even while I can plainly see that that input is filled with a value.即使我可以清楚地看到该输入填充了一个值,这也会始终记录一个空字符串。 However, as soon as I inspect or reference the element in Chrome devtools, the setInterval suddenly begins logging the correct value ( luke@deentaylor.com ):但是,一旦我在 Chrome devtools 中检查或引用该元素, setInterval就会突然开始记录正确的值( luke@deentaylor.com ):

Since the problem disappears as soon as one attempts to debug it, this has been extremely difficult to diagnose.由于一旦尝试调试问题就会消失,因此诊断非常困难。 What could cause this?什么可能导致这种情况?

EDIT: never mind, this behavior has nothing to do with the inspection of the element itself, a console.log('hi') in the console produces the same result.编辑:没关系,这种行为与元素本身的检查无关,控制台中的console.log('hi')会产生相同的结果。 The prerequisite for filling the correct form value is just for the user to interact with the page.填写正确的表单值的前提是用户与页面交互。 Unlike the solutions here , I do need the full autofilled value;这里的解决方案不同,我确实需要完整的自动填充值; my login form needs to make a request to the server with the contents of the field before enabling the "submit" button.在启用“提交”按钮之前,我的登录表单需要使用该字段的内容向服务器发出请求。

I believe this is just expected behavior for Chrome's autofill.我相信这只是 Chrome 自动填充的预期行为。 See this question.看到这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM