jquery - VueJs 在选择选项中设置自定义属性值

标签 jquery laravel vue.js

我正在使用 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/

相关文章:

php - 如何在Linux服务器中执行laravel artisan命令

javascript - Vue.js 显示从另一个组件调用一个组件

vue.js - Vuex-如何在不同选项卡之间持久存储更新?

javascript - jquery自动刷新页面

javascript - .focus() 不适用于输入,而其他属性则有效

laravel - 如何在 Laravel 5 中保护图像不被公众看到?

php - 在 Laravel 5 中从数据库渲染 html 图像标签

vue.js - Bootstrap Vue datepicker对于prop max,期望的字符串,日期和日期都失败

javascript - 以数组形式读取和写入数据到 cookie

javascript - 将 jQuery 输入插入表模板