Created
April 4, 2017 21:10
-
-
Save lkostrowski/19cf6862cd7e11b33e174f82b4fef29a to your computer and use it in GitHub Desktop.
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
<template> | |
<ul class="products-list"> | |
<slot v-if="!products.length" name="empty-basket"></slot> | |
<loader v-if="!loaded"></loader> | |
<basket-product v-else | |
v-for="(product, index) in products" | |
:key="index" | |
:product-data="product" | |
class="products-list__product" | |
@remove="_removeProductHandler"> | |
</basket-product> | |
</ul> | |
</template> | |
<script> | |
import eventBus from 'services/event-bus' | |
import productService from 'services/product' // We will write ajax delete call here | |
export default { | |
name: 'products-list', | |
data() { | |
return { | |
products: [], | |
loaded: false | |
}; | |
}, | |
created() { | |
eventbus.$emit('basketpage:loaded'); | |
eventBus.$on('basket:loading', () => { | |
this.loaded = false; | |
}); | |
eventBus.$on('basket:updated', (data) => { | |
this.products = data.products; | |
this.loaded = true; | |
}); | |
}, | |
methods: { | |
_removeProductHandler (data) { | |
// Call service to remove product and pass data | |
productService.removeProduct(data.id) | |
} | |
} | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment