Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
185
rated 0 times [  188] [ 3]  / answers: 1 / hits: 62552  / 7 Years ago, tue, august 8, 2017, 12:00:00

I just want to determine whether a checkbox is checked or not in Vue js 2. In jquery we have functions like $('input[type=checkbox]').prop('checked'); which will return true if checkbox is checked or not. What is the equivalent function in Vue js.



Here is the scenario with code. Please note i am using laravel with its blade templates.



@foreach ($roles as $role)
<input type=checkbox v-on:click=samplefunction({{$role->id}}) v-model=rolesSelected value={{$role->id}}>
@endforeach


The js part is



<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>

More From » laravel

 Answers
27

You can do something like:


if(this.rolesSelected != "") {
alert('isSelected');
}

or
v-on:click="samplefunction({{$role->id}},$event)"


samplefunction : function(value,event) {
if (event.target.checked) {
alert('isSelected');
}
}

[#56837] Friday, August 4, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jack

Total Points: 557
Total Questions: 96
Total Answers: 80

Location: Saint Helena
Member since Mon, Jan 16, 2023
1 Year ago
;