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.

下面是带有代码的场景.请注意,我正在使用laravel及其Blade 模板.

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

推荐答案

你可以这样做:

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

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

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

Laravel相关问答推荐

如何在 Laravel 中获取特定月份的最后一个日期?

如何从laravel中的另一个表中获取用户名

使用 App::environment() 与 app()->environment() 与 config('app.env') 之间的区别

"public/index.php" 可以在 laravel 中按组写入

自定义 Laravel 关系?

覆盖 HTTP 标头的默认设置 (X-FRAME-OPTIONS)

查询 Laravel Select WhereIn 数组

使用 Eloquent (Laravel) 在 Group By 之前排序

从 Laravel Cashier 获取下一个账单日期

如何处理 laravel 5 中的私有图像?

在 php Laravel 5 中创建自定义帮助函数的最佳实践是什么?

laravel 5.4 指定的key太长,为什么数字191

如何处理 php (Laravel api) 和 javascript (AngularJS) 之间的日期时间

防止 Eloquent 查询上的模型水合

Laravel Eloquent 查询生成器默认 Where 条件

Guzzle 返回流空体而不是 json 体

Laravel Queue,Beanstalkd vs Database,有什么区别?

Laravel 获取查询字符串

使用 Nginx 设置 Laravel

Laravel 部署……有标准的方式吗?