Skip to content

Commit

Permalink
add router, change FE code
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Nov 27, 2023
1 parent f92a0a2 commit 3dfbdb7
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 17 deletions.
3 changes: 3 additions & 0 deletions ShoppingCart/Frondend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

```bash
vue create ecommerce-ui

# Run the following command in your command line to install the Vue router in your system
vue add router
```

## Run
Expand Down
47 changes: 47 additions & 0 deletions ShoppingCart/Frondend/ecommerce-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,50 @@ npm run lint

### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).


### Vue intro

#### Code structure

```javascript
<template>
<!-- HTML Template -->
</template>

<script>
export default {}
</script>

<style>
</style>
```

The template part contains the HTML of the component.

The script tag contains the code defining the custom behavior of the component.

The style tag houses the CSS of the component.

src/components and src/views contain all our components.

#### Folder Structure

Let’s go through the folder structure of our newly created Vue project

*public *— contains the main HTML file of our project

*src/assets *— stores the media files like images, logos, etc.

*src/components *— stores all the reusable components of our project. These components are not unique to some specific route.

Apart from this, we have some important files too

*App.vue *— it is the root component of our project

main.js **— it is the starting point of our project. Here we import our root component **App.vue, our router file index.js and createApp method. After this, we mount our root component to the DOM using the following statement:

new Vue({
render: h => h(App),
}).$mount('#app')

14 changes: 13 additions & 1 deletion ShoppingCart/Frondend/ecommerce-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion ShoppingCart/Frondend/ecommerce-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
},
"dependencies": {
"core-js": "^3.8.3",
"vue": "^2.6.14"
"vue": "^2.6.14",
"vue-router": "^3.5.1"
},
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16",
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-plugin-router": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3",
Expand Down
32 changes: 18 additions & 14 deletions ShoppingCart/Frondend/ecommerce-ui/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
<nav>
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>
</nav>
<router-view/>
</div>
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'
export default {
name: 'App',
components: {
HelloWorld
}
}
</script>

<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
nav {
padding: 30px;
}
nav a {
font-weight: bold;
color: #2c3e50;
}
nav a.router-link-exact-active {
color: #42b983;
}
</style>
6 changes: 5 additions & 1 deletion ShoppingCart/Frondend/ecommerce-ui/src/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import Vue from 'vue'
import App from './App.vue'
import router from './router'

/** APP ENTRY POINT */

Vue.config.productionTip = false

new Vue({
render: h => h(App),
router,
render: h => h(App)
}).$mount('#app')
29 changes: 29 additions & 0 deletions ShoppingCart/Frondend/ecommerce-ui/src/router/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
{
path: '/',
name: 'home',
component: HomeView
},
{
path: '/about',
name: 'about',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
}
]

const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})

export default router
5 changes: 5 additions & 0 deletions ShoppingCart/Frondend/ecommerce-ui/src/views/AboutView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>
18 changes: 18 additions & 0 deletions ShoppingCart/Frondend/ecommerce-ui/src/views/HomeView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'
export default {
name: 'HomeView',
components: {
HelloWorld
}
}
</script>

0 comments on commit 3dfbdb7

Please sign in to comment.