Created
January 2, 2019 11:34
-
-
Save fredyfx/1c2386e265593de3dc36c0e6db4bfb2d to your computer and use it in GitHub Desktop.
archivo final del tutorial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = new Vue({ | |
el: "#primervue", | |
data: { | |
titulo: "Primeros pasos con VueJS y el buen @fredyfx" | |
} | |
}); | |
var app2 = new Vue({ | |
el: "#segundovue", | |
data: { | |
productos: [], | |
producto: { | |
nombre: "", | |
stock: "", | |
tieneOferta: true, | |
id: 0 | |
}, | |
mostrarBotonRegistrar: true | |
}, | |
methods: { | |
obtenerLista: function() { | |
this.$http.get("http://localhost:5000/api/producto") | |
.then(function(respuesta) { | |
this.productos = respuesta.body; | |
}, function() { | |
alert("Entra en modo Detective Zen y encuentra la causa del error"); | |
}).then(function() { | |
console.log("Finalmente tenemos: "); | |
console.log(this.productos); | |
}); | |
}, | |
enviarFormulario: function() { | |
console.log("Enviando datos al servidor"); | |
if (this.producto.id == 0) { | |
this.$http.post("http://localhost:5000/api/producto", this.producto) | |
.then(function(respuesta) { | |
console.log("lo que viene del server: "); | |
console.log(respuesta); | |
}, function() { | |
alert("Entra en modo Detective Zen y encuentra la causa del error"); | |
}).then(function() { | |
console.log("Finalmente: "); | |
console.log("Producto creado"); | |
}); | |
} else { | |
this.actualizarProducto(this.producto.id); | |
} | |
this.limpiarFormulario(); | |
this.obtenerLista(); | |
}, | |
limpiarFormulario: function() { | |
this.producto = { | |
nombre: "", | |
stock: "", | |
tieneOferta: true, | |
id: 0 | |
}, | |
this.mostrarBotonRegistrar = true; | |
}, | |
obtenerProducto: function(elemento) { | |
console.log("ID Seleccionado: ", elemento); | |
this.$http.get("http://localhost:5000/api/producto/" + elemento, this.producto) | |
.then(function(respuesta) { | |
this.producto = respuesta.body; | |
}, function() { | |
alert("Entra en modo Detective Zen y encuentra la causa del error"); | |
}).then(function() { | |
console.log("obtenerProducto: "); | |
console.log(this.producto); | |
}); | |
this.mostrarBotonRegistrar = false; | |
}, | |
actualizarProducto: function(elemento) { | |
console.log("actualizando producto:", elemento); | |
this.$http.put("http://localhost:5000/api/producto/" + elemento, this.producto) | |
.then(function(respuesta) { | |
console.log("producto actualizado!"); | |
}, function() { | |
alert("Entra en modo Detective Zen y encuentra la causa del error"); | |
}).then(function() { | |
console.log("actualizarProducto: "); | |
}); | |
}, | |
eliminarProducto: function(elemento) { | |
console.log("ID Seleccionado: ", elemento); | |
this.$http.delete("http://localhost:5000/api/producto/" + elemento) | |
.then(function(respuesta) { | |
console.log("producto eliminado"); | |
}, function() { | |
alert("Entra en modo Detective Zen y encuentra la causa del error"); | |
}); | |
this.obtenerLista(); | |
} | |
}, | |
created: function() { | |
console.log("funcion creada"); | |
this.obtenerLista(); | |
} | |
}); | |
console.log("aqui se supone que hay un archivo extenso de javascript"); | |
console.log("powered by @fredyfx"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment