Skip to content

Commit

Permalink
fix api call in Product.vue, add Admin.vue, fix code format
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Nov 29, 2023
1 parent 655aea5 commit aca94d0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
14 changes: 4 additions & 10 deletions ShoppingCart/Frondend/ecommerce-ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
delcare global variable via router view
-> so baseURL, categories are visible to ALL views
-->
<router-view
:baseURL="baseURL"
:categories="categories"
>
</router-view>
<router-view :baseURL="baseURL" :categories="categories"> </router-view>
</div>
</template>

Expand All @@ -37,19 +33,17 @@ export default {
},
methods: {
async fetchData() {
// fetch products
// fetch products
await axios
.get(this.baseURL + 'product/')
.get(this.baseURL + "product/")
.then((res) => (this.products = res.data))
.catch((err) => console.log(err));
//fetch categories
await axios
.get(this.baseURL + 'category/')
.get(this.baseURL + "category/")
.then((res) => (this.categories = res.data))
.catch((err) => console.log(err));
},
},
Expand Down
6 changes: 6 additions & 0 deletions ShoppingCart/Frondend/ecommerce-ui/src/views/Admin.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<div class="admin">
<h1>This is Admin page</h1>
</div>
</template>

28 changes: 27 additions & 1 deletion ShoppingCart/Frondend/ecommerce-ui/src/views/Product/Product.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,37 @@
</template>

<script>
// https://youtu.be/VZ1NV7EHGJw?si=JPmnA7oQoVdPJwAL&t=1450
// https://github.com/webtutsplus/ecommerce-vuejs/blob/master/src/views/Product/Product.vue
import ProductBox from '../../components/Product/ProductBox';
var axios = require('axios');
export default {
name: 'Product',
components : {ProductBox},
props : [ "baseURL" , "products" ],
//props : [ "baseURL" , "products" ],
props : [ "baseURL" ],
data() {
return {
//baseURL : "https://limitless-lake-55070.herokuapp.com/",
//baseURL: "http://localhost:9999/",
products : [],
}
},
methods: {
async getProducts() {
//fetch categories
await axios.get(this.baseURL + "product/")
.then(res => this.products = res.data)
.catch(err => console.log(err))
}
},
mounted(){
this.getProducts();
}
// mounted(){
// if (this.$route.name=='AdminProduct' && !localStorage.getItem('token')) {
// this.$router.push({name : 'Signin'});
Expand Down

0 comments on commit aca94d0

Please sign in to comment.