如何在v模型更改时触发事件? (vue js)
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启动foo()函数,但正如您所看到的,需要按两次单选按钮才能正确触发事件。只有第二次按下时才能抓住价值......
I want to fire the event without @click
only fire the event when v-model
(srStatus) changes.
我想在没有@click的情况下触发事件,只在v-model(srStatus)发生变化时触发事件。
here is my Fiddle:
这是我的小提琴:
http://fiddle.jshell.net/wanxe/vsa46bw8/
4 个解决方案
#1
32
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
Also, make sure you really want to call foo()
on ready... seems like maybe you don't actually want to do that.
此外,确保你真的想要准备好调用foo()...似乎你可能实际上并不想这样做。
ready:function(){
foo();
},
更多相关文章
- python模拟多次采样通过低概率事件多次重复实验趋近必然事件
- 由ajax [duplicate]生成时,formset的提交按钮不起作用
- 初学者的Selenium自动化测试指南,基于Python(五)——常用键盘事件
- 从django视图中的按钮获取click事件
- Telnet套接字网关到Coldfusion事件网关,连接到Asterisk AMI
- 我如何在Linux和Python中监听“usb设备插入”事件?
- 清华大学出版社“抄袭事件”回放
- Inotify: 高效、实时的Linux文件系统事件监控框架
- mysql创建任务事件