Reputation: 493
52:7 error Duplicated key 'order' vue/no-dupe-keys
I am now trying to illustrate only {order.id}, but this is the fist time to use Vue.js, therefore I am not sure how to fix it. Also, my final achievement would be each column has {{item.image}},{{item.price}},{{item.qty}},{{item.amount}}.
OverDetailVue
<template>
<div class="OrderListing">
<h2>Order Detail</h2>
<table class="table">
<tr>
<th>Product</th>
<th>Price</th>
<th>qty</th>
<th>Amount</th>
</tr>
<tr v-for="order in this.orders" :key="order.id">
<td>{{ order.price }}</td>
<td>{{ item.qty }}</td>
<td>{{ item.total }}</td>
</tr>
</table>
<tr class="total-row">
<td>TOTAL:</td>
<td></td>
<td></td>
<td>{{ total }}</td>
<td></td>
</tr>
</div>
</template>
<script>
import axios from "axios";
export default {
name: 'OrderListing',
computed: {
items: function() {
return this.$root.$data.cart.items || [];
},
total: function() {
let sum = 0
for (const item of this.items) {
sum += item.total
}
return sum
}
},
props: {
order: Object
},
data: function() {
return {
order: {}
}
},
mounted() {
axios
.get("https://euas.person.ee/orders/" + this.$route.params.orderId)
.then(response => {
this.orders = response.data;
}).catch(error => {
console.log(error);
})
}
}
</script>
<style scoped>
.option-image {
max-height: 75px;
max-width: 150px;
}
</style>
Upvotes: 0
Views: 5715
Reputation: 493
<template>
<div class="OrderListing">
<h2>Order Detail</h2>
<table class="table">
<tr>
<th>Product</th>
<th>Price</th>
<th>qty</th>
<th>Amount</th>
</tr>
<tr v-for="(item, index) in this.order.items" :key="item.productId + '_' + index">
<td>
<img :src="item.optionImage" class="option-image" />
</td>
<td>{{ item.price }}</td>
<td>{{ item.qty }}</td>
<td>{{ item.total }}</td>
</tr>
<tr class="total-row">
<td>TOTAL:</td>
<td></td>
<td></td>
<td>{{ total }}</td>
</tr>
</table>
</div>
</template>
<script>
import axios from "axios";
export default {
name: 'OrderListing',
computed: {
items: function() {
return this.$root.$data.cart.items || [];
},
total: function() {
let sum = 0
for (const item of this.items) {
sum += item.total
}
return sum
}
},
data: function() {
return {
order:{}
}
},
mounted() {
axios
.get("https://euas.person.ee/user/orders/" + this.$route.params.orderId)
.then(response => {
this.order = response.data;
}).catch(error => {
console.log(error);
})
}
}
</script>
<style scoped>
.option-image {
max-height: 75px;
max-width: 150px;
}
</style>
Upvotes: 1