search

Home  >  Q&A  >  body text

javascript - How to bind events only when conditions are met in vue


 <button @click.prevent="getVerifyCode">获取验证码</button>

For example, a line of code like this, assuming I have a variable like isRightPhoneNumber, I hope that the above button will be enabled only when my isRightPhoneNumber is true What should I do if the event takes effect? One way I thought of is to add judgment in the getVerifyCode function, like this

if(!this.isRightPhoneNumber) return;

But I don’t really want to use this method, so I would like to ask if there is any other method, is there any method similar to v-if

{{messageLogin?'登录':'密码登录'}}
<form class='message-form' v-if='messageLogin'></form>
高洛峰高洛峰2754 days ago669

reply all(1)I'll reply

  • 迷茫

    迷茫2017-05-16 13:38:29

    :disabled="!isRightPhoneNumber"

    reply
    0
  • Cancelreply