我正在使用 vuejs 和 laravel .. 我想要的是访问名为价格的自定义属性,如下所示..
<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' >
在控制台中,我得到文本'unit.price'
,而不是来自循环中的 v-for 的真实数字..
那么我如何根据unit.price设置属性价格..
谢谢..
最佳答案
您需要绑定(bind)price
属性。 binding attribute
<option v-for='(unit) in line.units' :price='unit.price'>
关于jquery - VueJs 在选择选项中设置自定义属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61965572/