In vue, if the attribute change of the element is controlled by keydown to the input element, there will be a situation that it cannot be entered.

the official reply is that the attribute change will lead to the overall element render , not setAttribute . Thank you for your answer. Give + 1
official reply

. < hr >

probably guessed , whether the property change caused the logic of the render inside the render, vue to re-read the value on the props for re-rendering, so the following situation occurred. Please reply and confirm if you have seen the vue source code, 3Q.

Demo

< hr >

is this the bug? of vue

?

browser: mac Google 68
vue: 2.5.16 & & 2.5.17

reproduce 1

reproduce 2

Code:

<div id="app">
  <input :warning="hasWarning" :value="text" @keydown="keydown" />
</div>
new Vue({
  el: "-sharpapp",
  data: {
    text: "vue",
    hasWarning: false
  },
  methods: {
      keydown() {
      if (1 == 1) {
          this.hasWarning = true;
      }
      this.hasWarning = false;
    }
  }
})
Apr.06,2021

change: value= "text" to vMube model = "text"

I think you use: value just assigns the initial value of the text variable to input, but the change in the value of input does not change the text variable, so the value has not changed.
if you want to unify the two, you still have to use v-model for two-way binding

it will be troublesome to manually modify the this.text, in the keydown method every time without two-way binding.


you directly use : value= "text" is equivalent to one-way binding. Every time vue resets render, it will reset input to the value of text, that is, 'vue',' you have assigned hasWarning in your keydown, which will trigger render, so the value of input will become 'vue'.. This can also be well understood from your first demonstration. You change num, every second to trigger render, so every second the value of input will be reset to vue.


is not a problem with keydown. Value is changed according to text, and you need to change text


in keydown. How can you tell that the hasWarning attribute has not changed?


Change

to

keydown() {
      if (1 == 1) {
          this.hasWarning = true;
      }else {
          this.hasWarning = false;
      }
      
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf5b91-30ce6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf5b91-30ce6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?