How to conditionally call the "activate" method when the user presses the Enter key?
I was hoping the following would work, but it doesn't:
<input type="text" v-model="code" v-on:keyup.enter="code.match(/^\d{6}$/) ? activate : null"> methods: { activate() { ... },
P粉4251197392024-03-27 15:01:11
Try this method. Move the logic to another method and call activation from that method if the conditions for calling activation are met.
methods: { keyPressed() { if(this.code.match(/^\d{6}$/)){ activate() } }, activate() { ... } }