猿问

V-bind怎么绑定自定义的属性啊比如data-id什么的

比如下面遍历的时候有个自定义属性data-id要放值,该怎么放啊,下面这样是不行的

<template v-for="region in regions">

    <option :value="region.region_id" :data-id='region.xx'>{{ region.region_name }}</option>

</template>


慕容708150
浏览 1844回答 1
1回答

慕莱坞森

写了一个简单的例子&nbsp;<body>&nbsp; &nbsp; <div id="app">&nbsp; &nbsp; &nbsp; <select>&nbsp; &nbsp; &nbsp; &nbsp; <template v-for="region in regions">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option :value="region.region_id" :data-id="region.xx">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {{ region.region_name }}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </option>&nbsp; &nbsp; &nbsp; &nbsp; </template>&nbsp; &nbsp; &nbsp; </select>&nbsp; &nbsp; </div>&nbsp; &nbsp; <script>&nbsp; &nbsp; &nbsp; new Vue({&nbsp; &nbsp; &nbsp; &nbsp; el: "#app",&nbsp; &nbsp; &nbsp; &nbsp; data() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; regions: [{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; region_id: 1,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xx: "hello",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; region_name: "name"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; </script>&nbsp; </body>效果截图如下,是好使的:
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答