NestedList.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <v-list class="py-0" dense>
  3. <div v-for="category in categories" :key="category.id">
  4. <template>
  5. <v-list-item @click="">
  6. <v-col cols="10">
  7. <div :style="indent">{{ category.title }}</div>
  8. </v-col>
  9. <v-col cols="2" class="text-right">
  10. <v-btn link tile color="success" @click="$emit('edit', category)">
  11. <v-icon center> mdi-pencil</v-icon>
  12. </v-btn>
  13. <v-btn
  14. tile
  15. color="error"
  16. @click="$emit('delete', category)"
  17. :disabled="isDisabled(category)"
  18. >
  19. <v-icon center> mdi-delete-outline </v-icon>
  20. </v-btn>
  21. </v-col>
  22. </v-list-item>
  23. <category-list
  24. v-if="category.child.length"
  25. @edit="$emit('edit', $event)"
  26. @delete="$emit('delete', $event)"
  27. :depth="depth + 1"
  28. :categories="category.child"
  29. ></category-list>
  30. </template>
  31. </div>
  32. </v-list>
  33. </template>
  34. <script>
  35. export default {
  36. name: "category-list",
  37. props: ["categories", "depth"],
  38. computed: {
  39. indent() {
  40. return { paddingLeft: `${this.depth * 20}px` };
  41. },
  42. },
  43. methods: {
  44. isDisabled(category) {
  45. return Boolean(category.news_count) || Boolean(category.child.length);
  46. },
  47. },
  48. };
  49. </script>