-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathCustomers.vue
77 lines (66 loc) · 2.08 KB
/
Customers.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<style scoped>
.addmargin {
margin-top: 10px;
margin-bottom: 10px;
}
.vue-logo-back {
background-color: black;
}
</style>
<template>
<div class="home">
<div class="vue-logo-back">
<img src="../assets/logo.png" width="100px" height="100px">
</div>
<div class="col-md-6 centeralign">
<p>This Page Displays a list of customers</p>
<p>Clicking on a Card Displays the name below. This is to demonstrate passing data from parent to child component</p>
<p>"Click for more details" Redirects to a new page which displays the customer information</p>
<div class="card centeralign addmargin" style="width: 18rem;" v-for="customer in customerlist" :key="customer.id">
<div class="card-body" v-on:click="setSelectedCustomer(customer.name)">
<h5 class="card-title">{{customer.name}}</h5>
<p class="card-text">{{customer.email}}</p>
<p class="card-text">{{customer.phone}}</p>
<a class="btn btn-primary" v-on:click="goToDetailsPage(customer.id)"><span style="color:white">Click for more details</span></a>
</div>
</div>
</div>
<Display v-if="selectedCustomer!=''" :selectedCustomer="selectedCustomer" />
</div>
</template>
<script>
// @ is an alias to /src
import Display from '@/components/Display.vue'
import axios from 'axios'
export default {
name: 'customers',
mounted() {
axios({
method: "GET",
"url": "assets/samplejson/customerlist.json"
}).then(response => {
this.customerlist = response.data;
}, error => {
// eslint-disable-next-line
console.error(error);
});
},
data() {
return {
customerlist: [],
selectedCustomer: ""
}
},
components: {
Display
},
methods: {
setSelectedCustomer: function(name) {
this.selectedCustomer = name;
},
goToDetailsPage: function(id) {
this.$router.push("/customerdetails/"+id);
}
}
}
</script>