Skip to content

Instantly share code, notes, and snippets.

@VinSpee
Created March 2, 2018 03:52
Show Gist options
  • Save VinSpee/364b7640b06e1b31e43911482e6031b4 to your computer and use it in GitHub Desktop.
Save VinSpee/364b7640b06e1b31e43911482e6031b4 to your computer and use it in GitHub Desktop.
const Home = {
template: `
<div>
<div v-if="loading">
Loading…
</div>
<ol>
<li v-for="product in products">
<router-link style="display: block;" v-bind:to="getProductURL(product.id)">
<div>
{{product.product}}
</div>
<div>
{{product.description}}
</div>
</router-link>
</li>
</ol>
</div>
`,
methods: {
...mapActions([
'fetchProducts',
]),
getProductURL(id) {
return `/products?id=${id}`;
},
},
created() {
if (!this.products.length) {
this.fetchProducts();
}
},
computed: {
products() {
return this.$store.getters.products;
},
loading() {
return this.$store.getters.loading;
},
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment