Skip to content

Commit

Permalink
Acciones
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan committed Jan 25, 2020
1 parent 8fb8ab1 commit cb5fab4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/components/AppProductList.vue
Expand Up @@ -12,14 +12,14 @@
</template>

<script>
import api from "../api/shop.js";
export default {
name: "AppProductList",
created() {
api.getProducts(products => {
// this.products = products;
this.$store.commit("setProducts", products);
});
async created() {
try {
await this.$store.dispatch("getProducts");
} catch (error) {
console.error(error);
}
},
computed: {
products() {
Expand Down
12 changes: 11 additions & 1 deletion src/store/index.js
@@ -1,5 +1,6 @@
import Vue from "vue";
import Vuex from "vuex";
import api from "../api/shop.js";

Vue.use(Vuex);

Expand All @@ -12,6 +13,15 @@ export default new Vuex.Store({
state.products = products;
}
},
actions: {},
actions: {
getProducts({ commit }) {
return new Promise(resolve => {
api.getProducts(products => {
commit("setProducts", products);
resolve();
});
});
}
},
modules: {}
});

0 comments on commit cb5fab4

Please sign in to comment.