Vue+element button button bind enter key event

< template >

<div>
    <userDetail v-if="userdetailShow"></userDetail>
    <el-button @click="detailShow"></el-button>
</div>

< / template >

data () {

return{
    userdetailShow:false
}

}

created () {

this.keyupSubmit()

},
methods: {
/ / listen for carriage return events

keyupSubmit(){
  document.onkeydown=e=>{
    let _key=window.event.keyCode;
    if(_key===13){
      this.adduser()
    }
  }
},
detailShow(){
    this.userdetailShow=true
}

}

there is a definite button button in the userdetai component, which listens to the carriage return event code in the userdetail component, and globally binds the method adduser () {/ p > in the carriage return event component.

this.userdetailShow=false
}

the enter event binding succeeded, but the display property of userdetail, the dailog component v-if binding, changes from true to false to true after the enter event.

according to the requirements and the logic of the code, the functions bound by the carriage return event are all run, but I don"t know why the thsi.userdetailShow=false has become true

.

but if the dailog component pops up, if you click dailog and give the dailog focus, this situation will not happen

ask what the reason is.

Mar.23,2021

try changing v-if to v-show!
v-if is a 'real' conditional rendering because it ensures that event listeners and subcomponents within the conditional block are properly destroyed and rebuilt during switching.

v-if is also lazy, and if the condition is false at the initial rendering, nothing is done-- the conditional block does not start to render until the condition is true for the first time, compared to
v-show

.

is much simpler-no matter what the initial condition is, the element is always rendered and simply switched based on css.

generally speaking, v-if has higher handover overhead,
and v-show has higher accident rendering overhead. Therefore, if you need to switch very frequently, it is better to use v-show; if

Runtime conditions are unlikely to change, so it's better to use v-if.

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-1b394d6-2c199.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-1b394d6-2c199.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?