-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrud-mascotas-vue.js
49 lines (46 loc) · 1.28 KB
/
crud-mascotas-vue.js
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
const { createApp } = Vue;
createApp({
data() {
return {
mascotas : [],
api_server:"http://127.0.0.1:8000",
id:'',
title:'',
descripción:'',
año_de_nacimiento:'',
banner:null
};
},
methods: {
getMascotas() { // Metodo para buscar las mascotas en el servidor
fetch(`${this.api_server}/api/mascotas/`)
.then((response) => response.json())
.then((data) => {
console.log(data);
this.mascotas = data;
})
.catch((err) => {
console.error(err);
});
},
getMascota(id_mascota) {
fetch(`${this.api_server}/api/mascotas/${id_mascota}/`, {
method: 'GET',
})
.then((response) => response.json())
.then((data) => {
this.id_mascota = data.id;
this.title = data.title;
this.descripción = data.descripción,
this.año_de_nacimiento = data.año_de_nacimiento
console.log(data);
})
.catch((error) => {
console.error("Error al enviar el formulario:", error);
});
},
},
created() {
this.getMascotas();
},
}).mount("#app");