Skip to content

Commit d355a1c

Browse files
committed
created vuex modules
1 parent 1339b95 commit d355a1c

File tree

24 files changed

+169
-92
lines changed

24 files changed

+169
-92
lines changed

public/index.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width,initial-scale=1.0">
77
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
8-
<title><%= htmlWebpackPlugin.options.title %></title>
8+
<title>How to Structure Vuex On Large Project</title>
9+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
10+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
11+
912
</head>
1013
<body>
1114
<noscript>
1215
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
1316
</noscript>
17+
<div class="container">
1418
<div id="app"></div>
19+
</div>
1520
<!-- built files will be auto injected -->
1621
</body>
1722
</html>

src/App.vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
<template>
2-
<div id="nav">
3-
<router-link to="/">Home</router-link> |
4-
<router-link to="/about">About</router-link>
5-
</div>
6-
<router-view/>
2+
<nav class="navbar navbar-expand-lg navbar-light bg-light">
3+
<div class="collapse navbar-collapse" id="navbarNav">
4+
<ul class="navbar-nav">
5+
<li class="nav-item">
6+
<router-link class="nav-link" to="/">Home</router-link>
7+
</li>
8+
</ul>
9+
</div>
10+
</nav>
11+
<router-view />
712
</template>
813

14+
<script>
15+
import { mapActions } from "vuex";
16+
17+
export default {
18+
created(){
19+
this.setMovies();
20+
},
21+
methods: {
22+
...mapActions('movies',['setMovies'])
23+
}
24+
}
25+
</script>
926
<style>
1027
#app {
1128
font-family: Avenir, Helvetica, Arial, sans-serif;

src/components/HelloWorld.vue

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/components/Movie.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<div class="card col-sm-4">
3+
<img class="card-img-top" :src="`https://image.tmdb.org/t/p/original${movie.poster_path}`" alt="Card image cap">
4+
<div class="card-body">
5+
<h5 class="card-title">{{ movie.title }}</h5>
6+
<p class="card-text">{{ movie.overview.substr(0,100)+'...' }}</p>
7+
<a href="#" class="btn btn-primary">View</a>
8+
</div>
9+
</div>
10+
</template>
11+
12+
<script>
13+
export default {
14+
name: "Movie",
15+
props: {
16+
movie: {
17+
type: Object,
18+
required: true
19+
}
20+
}
21+
}
22+
</script>
23+
24+
<style scoped>
25+
26+
</style>

src/components/Movies.vue

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<template>
2+
<div class="row">
3+
<Movie v-for="movie in getMovies" :movie="movie" :key="movie.id"/>
4+
</div>
5+
</template>
6+
7+
<script>
8+
import {mapGetters} from "vuex";
9+
import Movie from "@/components/Movie";
10+
export default {
11+
name: "Movies",
12+
components: { Movie },
13+
computed: {
14+
...mapGetters('movies', [ 'getMovies' ])
15+
}
16+
17+
}
18+
</script>
19+
20+
<style scoped>
21+
22+
</style>

src/router/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ const routes = [
77
name: 'Home',
88
component: Home
99
},
10-
{
11-
path: '/about',
12-
name: 'About',
13-
// route level code-splitting
14-
// this generates a separate chunk (about.[hash].js) for this route
15-
// which is lazy-loaded when the route is visited.
16-
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
17-
}
1810
]
1911

2012
const router = createRouter({

src/store/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { createStore } from 'vuex'
2+
import auth from './modules/auth';
3+
import movies from "./modules/movies";
4+
import notifications from "./modules/notifications";
25

36
export default createStore({
4-
state: {
5-
},
6-
mutations: {
7-
},
8-
actions: {
9-
},
107
modules: {
8+
auth,
9+
movies,
10+
notifications
1111
}
1212
})

src/store/modules/auth/actions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
3+
}

src/store/modules/auth/getters.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
getUserInformation: (state) => state.user
3+
}

src/store/modules/auth/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import state from './state';
2+
import getters from './getters';
3+
import mutations from './mutations';
4+
import actions from './actions'
5+
6+
export default {
7+
namespaced: true,
8+
state,
9+
getters,
10+
mutations,
11+
actions,
12+
};

0 commit comments

Comments
 (0)