Commit 26899cb0 authored by Mohammad Yousuf Khan's avatar Mohammad Yousuf Khan

Adds component to accept props from host app

parent c9576b4e
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="justify-content-md-center row"> <div class="justify-content-md-center row">
<div class="col col-lg-8"> <div class="col col-lg-8">
<top-bar></top-bar> <top-bar></top-bar>
<list-cart-items displaying="block"></list-cart-items> <list-cart-items displaying="block" :message="test"></list-cart-items>
<banner> <banner>
<div <div
class="card" class="card"
...@@ -30,8 +30,14 @@ ...@@ -30,8 +30,14 @@
<list-cart-items displaying="none"></list-cart-items> <list-cart-items displaying="none"></list-cart-items>
</div> </div>
</frequently-view> </frequently-view>
<suggest-product title="Customers Also Shopped" :list="list"></suggest-product> <suggest-product
<suggest-product title="Recently Viewed" :list="list"></suggest-product> title="Customers Also Shopped"
:list="list"
></suggest-product>
<suggest-product
title="Recently Viewed"
:list="list"
></suggest-product>
</div> </div>
<div class="col col-lg-4"> <div class="col col-lg-4">
<promo></promo> <promo></promo>
...@@ -59,8 +65,9 @@ export default { ...@@ -59,8 +65,9 @@ export default {
loading: false, loading: false,
}; };
}, },
props:{ props: {
productList: Array productList: Array,
test: Array,
}, },
components: { components: {
TopBar, TopBar,
...@@ -77,7 +84,7 @@ export default { ...@@ -77,7 +84,7 @@ export default {
.then((res) => res.json()) .then((res) => res.json())
.then((res) => { .then((res) => {
this.list = res; this.list = res;
console.log("===list", this.list) console.log("===list", this.list);
}) })
.finally(() => (this.loading = false)); // set loading to false when request finish .finally(() => (this.loading = false)); // set loading to false when request finish
}, },
......
...@@ -3,19 +3,24 @@ ...@@ -3,19 +3,24 @@
<div class="card" v-if="loading"> <div class="card" v-if="loading">
loading..... loading.....
</div> </div>
<div v-else class="overflow-hidden mb-2 card" v-for="item in list" v-bind:key="item.id"> <div
v-else
class="overflow-hidden mb-2 card"
v-for="item in message"
v-bind:key="item.id"
>
<div class="card-body"> <div class="card-body">
<div class="row no-gutters"> <div class="row no-gutters">
<div class="col col-lg-2"> <div class="col col-lg-2">
<img :src="item.image" alt="Image" class="rounded-0"/> <img :src="item.image" alt="Image" class="rounded-0" />
</div> </div>
<div class="col col-lg-6"> <div class="col col-lg-6">
<div :title="item.title"> <div :title="item.title">
<div class="card-text"> <div class="card-text">
<b>{{item.title }}</b> <b>{{ item.title }}</b>
<p>{{item.description}}</p> <p>{{ item.description }}</p>
<!-- <p>This is Dynamic {{ message }}</p> -->
</div> </div>
<br /> <br />
<br /> <br />
<div class="card-text"> <div class="card-text">
...@@ -25,7 +30,6 @@ ...@@ -25,7 +30,6 @@
Color: Red Color: Red
</div> </div>
</div> </div>
</div> </div>
<div class="col col-lg-2"> <div class="col col-lg-2">
<select v-model="selected"> <select v-model="selected">
...@@ -38,19 +42,24 @@ ...@@ -38,19 +42,24 @@
</div> </div>
<div class="col col-lg-2"> <div class="col col-lg-2">
<div class="card-text"> <div class="card-text">
<p>Orig. {{item.price }} </p> <p>Orig. {{ item.price }}</p>
<p class="red">Now {{item.price}} </p> <p class="red">Now {{ item.price }}</p>
<p class="grey">Subtotal {{item.price}} </p> <p class="grey">Subtotal {{ item.price }}</p>
<br/> <br />
<br/> <br />
<p><b>Total {{item.price * selected}} </b></p> <p>
<b>Total {{ item.price * selected }} </b>
</p>
</div> </div>
</div> </div>
</div> </div>
<div :style="displaying"> <div :style="displaying">
<div> <div>
<p><b>Sihip it </b></p> <p><b>Sihip it </b></p>
<p> <span class="green">In Stock: </span> Usually ships within 3 business days.</p> <p>
<span class="green">In Stock: </span> Usually ships within 3
business days.
</p>
</div> </div>
<div class="links"> <div class="links">
<a href="">Save For later </a> <a href="">Save For later </a>
...@@ -64,72 +73,68 @@ ...@@ -64,72 +73,68 @@
</template> </template>
<script> <script>
export default { export default {
name: "ListCartItems", name: "ListCartItems",
data() { data() {
return { return {
list: [], list: [],
loading: false, loading: false,
selected: '1', selected: "1",
} };
}, },
props: ['displaying'], props: ["displaying", "message"],
computed: { computed: {
getTotal : function(price) { getTotal: function(price) {
return price + this.selected return price + this.selected;
} },
}, },
methods: { methods: {
deleteCartItem(id) { deleteCartItem(id) {
fetch('https://fakestoreapi.com/products/'+ id) fetch("https://fakestoreapi.com/products/" + id).then((res) => {
.then((res)=> { console.log("==", res);
console.log("==", res) });
})
var index = this.list.map(x => { var index = this.list
.map((x) => {
return x.id; return x.id;
}).indexOf(id); })
.indexOf(id);
this.list.splice(index, 1); this.list.splice(index, 1);
} },
}, },
mounted() { mounted() {
this.loading = true //the loading begin this.loading = true; //the loading begin
fetch('https://fakestoreapi.com/products?limit=5') fetch("https://fakestoreapi.com/products?limit=5")
.then(res=> res.json()) .then((res) => res.json())
.then((res) => { .then((res) => {
this.list = res this.list = res;
}) })
.finally(() => (this.loading = false)) // set loading to false when request finish .finally(() => (this.loading = false)); // set loading to false when request finish
},
} };
}
</script> </script>
<style scoped> <style scoped>
.green { .green {
color:rgb(0, 135, 87) color: rgb(0, 135, 87);
}
} .red {
.red { color: rgb(224, 26, 43);
color: rgb(224, 26, 43) }
.grey {
} color: rgb(98, 99, 105);
.grey { }
color: rgb(98, 99, 105) p {
}
p {
margin: 0; margin: 0;
} }
.no-gutters { .no-gutters {
margin-bottom: 20px; margin-bottom: 20px;
} }
.links { .links {
margin-top: 20px; margin-top: 20px;
} }
.links a { .links a {
margin-right: 100px; margin-right: 100px;
} }
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment