当v型改变时如何触发事件? (vue js) [英] How to fire an event when v-model changes ? (vue js)

查看:151
本文介绍了当v型改变时如何触发事件? (vue js)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用v-on =click ...启动foo功能,但是您可以看到,需要按下单选按钮两次才能正确触发该事件。只需要第二次按下该值即可。

I'm trying to fire the "foo" function with the v-on="click ..." but as you can see, need press the radio button two times to fire the event correctly . Only catch the value the second time that you press...

我想在没有v-on =点击的情况下启动该事件;只有当v-model(srStatus)发生变化时才会触发事件。

I want to fire the event without v-on="click..."; only fire the event when v-model (srStatus) changes.

这是我的小提琴:

http://fiddle.jshell.net/wanxe/vsa46bw8/

推荐答案

这是因为您的点击处理程序在单选按钮的值更改之前触发。您需要听更改事件:

This happens because your click handler fires before the value of the radio button changes. You need to listen to the change event instead:

<input 
  type="radio" 
  name="optionsRadios" 
  id="optionsRadios2" 
  value=""
  v-model="srStatus" 
  v-on="change: foo"> //here

另外,确保你真的想调用 foo() 准备好了...似乎也许你实际上不想这样做。

Also, make sure you really want to call foo() on ready... seems like maybe you don't actually want to do that.

ready:function(){
    foo();
},

这篇关于当v型改变时如何触发事件? (vue js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆