checkboxList.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <div class="checkboxList">
  3. <el-checkbox-group v-model="List" @change="$emit('change', List)">
  4. <el-checkbox v-for="item in data" :key="item.id" class="checkbox" :label="item.id">{{ item.name }}</el-checkbox>
  5. </el-checkbox-group>
  6. </div>
  7. </template>
  8. <script>
  9. // const cityOptions = ['上海', '北京', '广州', '深圳', 'ss', 'qq', 'www', 'eeee', 'ssss', 'vvvv', 'ggg', 'jjj']
  10. export default {
  11. props: {
  12. selectedList: {
  13. type: Array,
  14. required: false,
  15. default: () => []
  16. },
  17. data: {
  18. type: Array,
  19. required: false,
  20. default: () => []
  21. }
  22. },
  23. data() {
  24. return {
  25. checkAll: false,
  26. // checkedCities: ['上海', '北京'],
  27. // cities: cityOptions,
  28. isIndeterminate: true,
  29. List: this.selectedList
  30. }
  31. },
  32. methods: {
  33. handleCheckAllChange(val) {
  34. // this.checkedCities = val ? cityOptions : []
  35. this.isIndeterminate = false
  36. },
  37. handleCheckedCitiesChange(value) {
  38. const checkedCount = value.length
  39. this.checkAll = checkedCount === this.cities.length
  40. this.isIndeterminate = checkedCount > 0 && checkedCount < this.cities.length
  41. }
  42. }
  43. }
  44. </script>
  45. <style scoped lang='scss'>
  46. .checkboxList {
  47. width: 800px;
  48. .checkbox {
  49. width: 130px;
  50. // margin-right: 50px;
  51. margin: 10px 0px;
  52. }
  53. }
  54. </style>