File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ [
2
+ { "id" : 1 , "name" : " Alice" },
3
+ { "id" : 2 , "name" : " Bob" },
4
+ { "id" : 3 , "name" : " Carol" },
5
+ { "id" : 4 , "name" : " David" }
6
+ ]
Original file line number Diff line number Diff line change @@ -5,6 +5,17 @@ import Texto from "./components/Texto.vue";
5
5
const mensagem = ref (" " );
6
6
const contador = ref (0 );
7
7
const showComponent = ref (true );
8
+ const items = ref ([]);
9
+
10
+ const fetchData = async () => {
11
+ try {
12
+ const response = await fetch (" ../public/data/nomes.json" );
13
+ const data = await response .json ();
14
+ items .value = data;
15
+ } catch (error) {
16
+ console .error (" O erro é: " , error);
17
+ }
18
+ };
8
19
9
20
function toggleComponent () {
10
21
showComponent .value = ! showComponent .value ;
@@ -18,6 +29,7 @@ function incrementar() {
18
29
onMounted (() => {
19
30
mensagem .value = " Componente Montado" ;
20
31
console .log (" onMounted executado" );
32
+ fetchData ();
21
33
});
22
34
23
35
// Antes de ser montado
@@ -43,4 +55,9 @@ onBeforeUpdate(() => {
43
55
<br />
44
56
<button @click =" toggleComponent" >Mostrar/Esconder</button >
45
57
<Texto v-if =" showComponent" />
58
+
59
+ <div v-if =" items.length === 0" >Carregando...</div >
60
+ <ul v-else >
61
+ <li v-for =" item in items" :key =" item.id" >{{ item.name }}</li >
62
+ </ul >
46
63
</template >
You can’t perform that action at this time.
0 commit comments