v-model 更改时如何触发事件? [英] How to fire an event when v-model changes?

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

问题描述

我正在尝试使用 @click 触发 foo() 函数,但如您所见,需要按两次单选按钮才能正确触发事件.仅在您第二次按下时捕捉该值...

I'm trying to fire the foo() function with the @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...

我想在没有 @click 的情况下触发事件,仅在 v-model (srStatus) 更改时触发事件.

I want to fire the event without @click only fire the event when v-model (srStatus) changes.

这是我的小提琴:

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

推荐答案

发生这种情况是因为您的 click 处理程序在单选按钮的值更改之前触发.你需要监听 change 事件:

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

另外,确保你真的想在 ready 时调用 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-model 更改时如何触发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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