Vue JS: Conditional logic inside v-on:keyup.enter
P粉394812277
P粉394812277 2024-03-26 17:41:08
0
1
467

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粉394812277
P粉394812277

reply all(1)
P粉425119739

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() {
          ...
         }
    }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template