index.vue 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <div>
  3. <template v-for="(item, index) in options">
  4. <template v-if="values.includes(item.dictValue)">
  5. <span
  6. v-if="item.listClass == 'default' || item.listClass == ''"
  7. :key="item.dictValue"
  8. :index="index"
  9. :class="item.cssClass"
  10. >{{ item.dictLabel }}</span
  11. >
  12. <el-tag
  13. v-else
  14. :key="item.dictValue"
  15. :index="index"
  16. :type="item.listClass == 'primary' ? '' : item.listClass"
  17. :class="item.cssClass"
  18. >
  19. {{ item.dictLabel }}
  20. </el-tag>
  21. </template>
  22. </template>
  23. </div>
  24. </template>
  25. <script>
  26. export default {
  27. name: "DictTag",
  28. props: {
  29. options: {
  30. type: Array,
  31. default: null,
  32. },
  33. value: [String, Array],
  34. },
  35. computed: {
  36. values() {
  37. if (this.value) {
  38. return Array.isArray(this.value) ? this.value : [this.value];
  39. } else {
  40. return [];
  41. }
  42. },
  43. },
  44. };
  45. </script>
  46. <style scoped>
  47. .el-tag + .el-tag {
  48. margin-left: 10px;
  49. }
  50. </style>