veujs在选择选项中设置自定义属性值

时间:2020-05-22 23:47:55

标签: jquery laravel vue.js

im与laravel一起使用vuejs 我想要的是访问名为price的自定义属性,如下所示:

<select name='unit[]' required @change='change_unit($event)'>
    <option v-for='(unit) in line.units' price='66'  :value='unit.get_unit_id.id'>@{{unit['get_unit_id']['name']}}</option>
</select>

这是vuejs代码

change_unit:function(event)
{
    let get_val = event.target.selectedOptions[0].getAttribute("price");
    console.log("Value from the Attribute: ", get_val)
}

像这样,一切都很好。 但是我的问题是,当我想基于v-for这样的价格设置价格时..

<option v-for='(unit) in line.units' price='unit.price' >

在控制台中,i gat文本'unit.price'不是实数来自循环中的v-for。 所以我该如何基于unit.price设置属性价格。 谢谢..

1 个答案:

答案 0 :(得分:3)

您需要绑定price属性。 binding attribute

<option v-for='(unit) in line.units' :price='unit.price'>
相关问题