File tree Expand file tree Collapse file tree 1 file changed +35
-3
lines changed
Expand file tree Collapse file tree 1 file changed +35
-3
lines changed Original file line number Diff line number Diff line change 11<template >
2- <div class =" box" v-if =" list.length > 0" v-for =" (item, index) in list" :key =" index" >
2+ <button v-if =" !isLoaded" class =" button is-loading my-custom-loader" >Carregando lista...</button >
3+ <div v-else-if =" list.length > 0" class =" box" v-for =" (item, index) in list" :key =" index" >
34 <div v-for =" [key, value] in Object.entries(sanitizeItem(item))" >
4- <div class =" subtitle" v-if =" isJsonLike(value)" >{{ key }}: {{ sanitizeItem(value) }}</div >
5+ <div class =" subtitle" v-if =" isJsonArray(value)" >
6+ {{ key }}: {{ value.map((v: any) => sanitizeItem(v)) }}
7+ </div >
8+ <div class =" subtitle" v-else-if =" isJsonLike(value)" >{{ key }}: {{ sanitizeItem(value) }}</div >
59 <div class =" subtitle" v-else >{{ key }}: {{ value || 'nenhum cadastrado' }}</div >
610 </div >
711 </div >
@@ -13,11 +17,25 @@ import { defineComponent, type PropType } from 'vue'
1317
1418export default defineComponent ({
1519 name: ' List' ,
20+ data() {
21+ return {
22+ isLoaded: false ,
23+ }
24+ },
25+ watch: {
26+ list: {
27+ immediate: false ,
28+ handler(newVal ) {
29+ if (newVal && newVal .length >= 0 ) {
30+ this .isLoaded = true
31+ }
32+ },
33+ },
34+ },
1635 props: {
1736 list: {
1837 type: Array as PropType <Array <Record <string , any >>>,
1938 required: true ,
20- default : () => [],
2139 },
2240 },
2341 methods: {
@@ -37,6 +55,20 @@ export default defineComponent({
3755 isJsonLike(value : any ): boolean {
3856 return typeof value === ' object' && value !== null && ! Array .isArray (value )
3957 },
58+ isJsonArray(value : any ): boolean {
59+ return (
60+ Array .isArray (value ) &&
61+ value .every ((item ) => typeof item === ' object' && item !== null && ! Array .isArray (item ))
62+ )
63+ },
4064 },
4165})
4266 </script >
67+
68+ <style scoped>
69+ .my-custom-loader {
70+ height : 50px ;
71+ width : 50px ;
72+ border-width : 5px ;
73+ }
74+ </style >
You can’t perform that action at this time.
0 commit comments