【问题标题】:Vuejs2 - how to use $(this).val()Vuejs2 - 如何使用 $(this).val()
【发布时间】:2018-10-28 07:47:14
【问题描述】:

我想在 vuejs2 中获取 select 选项的当前值。

我有这个 laravel 刀片代码:

<select  class='form-control units' @change='units' name='items_quantity_unit_id[]' required>
    @foreach($units as $unit)
        <option  class='form-control' value='{{$unit["id"]}}'>{{$unit['unit_name']}}</option>
    @endforeach
</select>

我有这个 vuejs2 代码

units:function(){
    var unit_id = $(this).val();
    console.log(unit_id);
}

现在,当我更改选择选项时,我收到此错误:

ncaught TypeError: Cannot read property 'toLowerCase' of undefined

那么当我更改 vuejs2 中的选项时,如何获取值。

谢谢

【问题讨论】:

    标签: php laravel vue.js vuejs2


    【解决方案1】:
    units:function(event){
      var unit_id = event.target.value;
      console.log(unit_id);
    }
    

    但我建议使用v-model,看看Form Input Bindings 指南。

    【讨论】:

    • 我如何通过单位传递参数:函数(事件,extra_parameter)
    • &lt;select @change="units($event, extra_parameter)"&gt; 或使用 v-model : &lt;select v-model="unit_id" @change="units(unit_id, extra_parameter)
    猜你喜欢
    • 2022-11-20
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多