-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
147 lines (133 loc) · 3.99 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Vue Carros</title>
<script src="vue.js"></script>
</head>
<body>
<div id="app" class="container">
<ul class="carros">
<li class="carros-item" :class="(item.slug == ativo ? 'ativo' : '')" v-for="item in carros" @click="fetchCarro(item.slug)">
<p>{{item.titulo}}</p>
<p>{{item.preco}}</p>
</li>
</ul>
<div class="carro" v-if="carro">
<transition name="entrar" mode="out-in" appear>
<div class="carro-item" :key="carro.slug">
<h1>{{carro.titulo}}</h1>
<img :src="carro.acf.foto" :alt="carro.titulo">
<ul class="carro-lista">
<li>Preço: {{carro.acf.preco}}</li>
<li>Ano: {{carro.acf.ano}}</li>
<li>Portas: {{carro.acf.portas}}</li>
<li v-if="carro.acf.novo">Novo</li>
<li v-else>Usado</li>
</ul>
</div>
</transition>
</div>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
carros: [],
carro: null,
ativo: ''
},
methods: {
fetchCarros() {
fetch('http://carro.local/wp-json/carcraft/v1/carros')
.then(resposta => resposta.json())
.then(respostaJSON => {
this.carros = respostaJSON;
})
},
fetchCarro(carro) {
fetch(`http://carro.local/wp-json/carcraft/v1/carro/${carro}`)
.then(resposta => resposta.json())
.then(respostaJSON => {
this.carro = respostaJSON;
this.ativo = respostaJSON.slug;
})
}
},
created() {
this.fetchCarros();
}
});
</script>
<style>
body {
background-color: #282a2d;
}
.container {
display: grid;
grid-template-columns: 200px 1fr;
max-width: 600px;
margin: 20px auto;
color: white;
}
img {
display: block;
max-width: 100%;
}
.carros {
padding: 0;
margin: 0;
list-style: none;
font-family: monospace;
font-size: 14px;
}
.carros li {
cursor: pointer;
padding: 15px;
margin-right: 20px;
border-bottom: 2px solid #0e1013;
}
.carros li p {
margin: 0;
}
.carros .ativo {
background-color: #0e1013;
}
.carro-item {
box-shadow: 0 2px 6px 1px rgba(0,0,0,.3);
border-radius: 4px;
padding: 20px 0;
background-color: #0e1013;
}
.carro-item h1 {
font-family: sans-serif;
margin: 0;
padding: 0 20px 15px 20px;
}
.carro-lista {
list-style: none;
display: grid;
grid-template-columns: 1fr 1fr;
padding: 0;
margin: 0 20px;
}
.carro-lista li {
font-family: monospace;
border: 2px solid #282a2d;
padding: 10px;
margin: -1px;
font-size: 14px;
font-style: italic;
}
.entrar-enter-active, .entrar-leave-active {
transition: all .3s;
}
.entrar-enter, .entrar-leave-to {
opacity: 0;
transform: translate(-20px, 0);
}
</style>
</body>
</html>