v模型更改时如何触发事件? [英] How to fire an event when v-model changes?
问题描述
我正在尝试使用@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
另外,请确保您确实想在准备好时呼叫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模型更改时如何触发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!