我只是想确定是否在Vue js 2中选中了复选框 . 在jquery中我们有 $('input[type=checkbox]').prop('checked'); 之类的函数,如果选中复选框,它将返回true . Vue js中的等价函数是什么 .
这是带代码的场景 . 请注意我使用laravel及其刀片模板 .
@foreach ($roles as $role)
<input type="checkbox" v-on:click="samplefunction({{$role->id}})" v-model="rolesSelected" value="{{$role->id}}">
@endforeach
js部分是
<script>
var app = new Vue({
el: '#app1',
data: {
rolesSelected:"",
},
methods : {
samplefunction : function(value) {
// Here i want to determine whether this checkbox is checked or not
}
},
});
</script>
2 回答
你可以这样做:
或
v-on:click="samplefunction({{$role->id}},$event)"
这对我有用 .