Skip to content

Commit aa488c9

Browse files
author
ahmadhuss
committed
feat: Added Vue.js component
1 parent 7b03d12 commit aa488c9

File tree

2 files changed

+74
-7
lines changed

2 files changed

+74
-7
lines changed

resources/js/components/Front.vue

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,48 @@
22

33
<!-- Template Part -->
44
<template>
5-
<div class="container">
5+
<div class="container" :class="{'loading': loading}">
6+
7+
<!-- Spinner will only appear if the private property `loading` is true. -->
8+
<div class="loading-wrapper" v-if="loading">
9+
<div class="spinner-border text-secondary" role="status">
10+
<span class="sr-only">Loading...</span>
11+
</div>
12+
</div>
613

714
<div class="row">
815

916
<div class="col-lg-3">
10-
1117
<h1 class="my-4">Shop Catalog</h1>
12-
18+
<div class="list-group" v-if="Array.isArray(categories) && categories.length > 0">
19+
<a :href="`/?category=${category.id}`" class="list-group-item" v-for="category in categories">
20+
{{ category.name }}
21+
</a>
22+
</div>
1323
</div>
1424
<!-- /.col-lg-3 -->
1525

1626
<div class="col-lg-9">
1727

18-
<div class="row my-5">
19-
28+
<div class="row my-5" v-if="Array.isArray(products) && products.length > 0">
29+
<div class="col-lg-4 col-md-6 mb-4" v-for="product in products">
30+
<div class="card h-100">
31+
<a :href="`/product/${product.name}`">
32+
<img class="card-img-top" src="http://placehold.it/700x400" alt="">
33+
</a>
34+
<div class="card-body">
35+
<h4 class="card-title">
36+
<a :href="`/product/${product.name}`">
37+
{{ _.capitalize (product.name) }}
38+
</a>
39+
</h4>
40+
<h5>${{ product.price }}</h5>
41+
<p class="card-text">
42+
{{ product.description }}
43+
</p>
44+
</div>
45+
</div>
46+
</div>
2047
</div>
2148
<!-- /.row -->
2249

@@ -31,7 +58,46 @@
3158

3259

3360
<!-- JavaScript Part -->
34-
<script></script>
61+
<script>
62+
export default {
63+
// Public properties
64+
data: function(){
65+
return {
66+
categories: [],
67+
products: [],
68+
loading: true
69+
}
70+
},
71+
// Private method runs before the component is mount on the screen
72+
mounted() {
73+
//console.log('Component is mounted!');
74+
this.loadCategories();
75+
this.loadProducts();
76+
},
77+
// Methods
78+
methods: {
79+
loadCategories: function (){
80+
// load API
81+
// assign this.categories
82+
// catch errors
83+
axios.get('/api/categories').then(response => {
84+
this.categories = response.data.data;
85+
}).catch(err => {
86+
console.log('API Promise rejected error :', err);
87+
}
88+
);
89+
},
90+
loadProducts: function (){
91+
axios.get('/api/products').then(response => {
92+
this.products = response.data.data;
93+
this.loading = false;
94+
}).catch(err => {
95+
console.log(err);
96+
});
97+
}
98+
}
99+
}
100+
</script>
35101

36102

37103

routes/web.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
|
1515
*/
1616

17-
Route::get('/', [HomeController::class, 'index']);
17+
// Just load the Blade File
18+
Route::view('/', 'home');

0 commit comments

Comments
 (0)