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