Usando vuex

This commit is contained in:
Alejandro Tasistro 2025-05-23 16:53:37 -03:00
parent 7140796ccd
commit d794dbd2b0

View file

@ -14,7 +14,7 @@
</span> </span>
<span class="file-label">Subir canasta</span> <span class="file-label">Subir canasta</span>
</span> </span>
<span class="file-name" v-if="archivo"> <span class="file-name" v-if="cargando">
{{ 'Cargando ' + archivo.nombre }} {{ 'Cargando ' + archivo.nombre }}
</span> </span>
</label> </label>
@ -24,6 +24,7 @@
<script> <script>
import axios from "axios"; import axios from "axios";
import { mapActions } from "vuex";
export default { export default {
name: "CanastaInput", name: "CanastaInput",
@ -34,10 +35,11 @@ export default {
}; };
}, },
methods: { methods: {
...mapActions('ui',["toast"]),
async archivoSubido(event) { async archivoSubido(event) {
const archivo = event.target.files[0]; const archivo = event.target.files[0];
if (archivo && archivo.type === "text/csv") { if (archivo && archivo.type === "text/csv") {
this.archivo = {data: archivo, nombre: archivo.name}; this.archivo = { data: archivo, nombre: archivo.name };
const formData = new FormData(); const formData = new FormData();
formData.append("data", this.archivo.data); formData.append("data", this.archivo.data);
@ -48,15 +50,15 @@ export default {
"Content-Type": "multipart/form-data", "Content-Type": "multipart/form-data",
}, },
}); });
this.$root.$toast(response.data.message || "Canasta cargada exitosamente"); this.toast({ mensaje: (response.data.message || "Canasta cargada exitosamente") });
} catch (error) { } catch (error) {
this.$root.$toast(error.response?.data?.message || "Hubo errores."); this.toast({ mensaje: (error.response?.data?.message || "Hubo errores.") });
} finally { } finally {
this.cargando = false; this.cargando = false;
this.archivo = null; this.archivo = null;
} }
} else { } else {
this.$root.$toast("La canasta debe ser .CSV") this.toast("La canasta debe ser .CSV")
this.archivo = null; this.archivo = null;
} }
}, },