欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue实现选中列表功能

程序员文章站 2022-05-16 21:25:16
...
<template>
  <div>
    <ul v-for="prop in items">
        <dt>{{prop.name}}</dt>
        <dd v-for="op in prop.options">
             <input type="checkbox" :value="op" v-model="selectedProperties">{{op.value}}
        </dd>
    </ul>
  {{selectedProperties}}<br />
  {{foos}}
  </div>
</template>

<script>
export default {
  computed:{
    foos(){
      return this.selectedProperties.map(item => item.value);
    }
  },
  data() {
    return {
      selectedProperties: [],
      items: [
                    {
                        "name": "容量", "type": 1, "options": [
                            { "id": "1", "value": "64G" },
                            { "id": "2", "value": "256G" }
                        ]
                    },
                    {
                        "name": "颜色", "type": 1, "options": [
                            { "id": "3", "value": "金色" },
                            { "id": "4", "value": "红色" }
                        ]
                    },
                    {
                        "name": "网络类型", "type": 1, "options": [
                            { "id": "5", "value": "4G全网通" },
                            { "id": "6", "value": "4G电信" },
                            { "id": "7", "value": "4G移动" }
                        ]
                    },
                    {
                        "name": "套餐类型", "type": 1, "options": [
                            { "id": "8", "value": "普通套餐" },
                            { "id": "9", "value": "高级套餐" }
                        ]
                    }
                ]
    }
  }
    }

</script>

 

相关标签: 前端