sreachTitle.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <template>
  2. <div :class="[count(val) > 0 ? 'item-title-active' : 'item-title']"><slot> </slot></div>
  3. </template>
  4. <script>
  5. export default {
  6. name: 'sreach-title',
  7. props: {
  8. val: { },
  9. },
  10. methods: {
  11. count(obj) {
  12. try {
  13. if (typeof obj === "undefined") {
  14. return 0;
  15. }
  16. if (typeof obj === "number" || obj instanceof Date) {
  17. obj+= "";
  18. }
  19. if (typeof obj.length === 'number') {
  20. if (typeof obj === 'object') {
  21. let i = 0
  22. $A.each(obj, (key, val) => {
  23. if (this.count(val) > 0) i++;
  24. });
  25. return i;
  26. }
  27. return obj.length;
  28. } else {
  29. let i = 0, key;
  30. for (key in obj) {
  31. if (this.count(obj) > 0) i++;
  32. }
  33. return i;
  34. }
  35. }catch (e) {
  36. return 0;
  37. }
  38. },
  39. }
  40. }
  41. </script>