Skip to content

Commit c87ac15

Browse files
committed
lesson15 changes
1 parent 1530449 commit c87ac15

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

src/App.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<template>
22
<div id="app">
33
<NavBar/>
4+
<NotificationContainer/>
45
<router-view :key="$route.fullPath" />
56
</div>
67
</template>
78

89
<script>
910
import NavBar from '@/components/NavBar.vue'
11+
import NotificationContainer from '@/components/NotificationContainer.vue'
1012
1113
export default {
1214
components: {
13-
NavBar
15+
NavBar,
16+
NotificationContainer
1417
}
1518
}
1619
</script>

src/components/NotificationBar.vue

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<template>
2+
<div class="notification-bar" :class="notificationTypeClass">
3+
<p>{{ notification.message }}</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
import { mapActions } from 'vuex'
9+
10+
export default {
11+
props: {
12+
notification: {
13+
type: Object,
14+
required: true
15+
}
16+
},
17+
data() {
18+
return {
19+
timeout: null
20+
}
21+
},
22+
mounted() {
23+
this.timeout = setTimeout(() => this.remove(this.notification), 5000)
24+
},
25+
beforeDestroy() {
26+
clearTimeout(this.timeout)
27+
},
28+
computed: {
29+
notificationTypeClass() {
30+
return `-text-${this.notification.type}`
31+
}
32+
},
33+
methods: mapActions('notification', ['remove'])
34+
}
35+
</script>
36+
37+
<style scoped>
38+
.notification-bar {
39+
margin: 1em 0 1em;
40+
}
41+
</style>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<template>
2+
<div class="notification-container">
3+
<NotificationBar
4+
v-for="notification in notifications"
5+
:key="notification.id"
6+
:notification="notification"
7+
/>
8+
</div>
9+
</template>
10+
11+
<script>
12+
import NotificationBar from '@/components/NotificationBar.vue'
13+
import { mapState } from 'vuex'
14+
15+
export default {
16+
components: {
17+
NotificationBar
18+
},
19+
computed: mapState('notification', ['notifications'])
20+
}
21+
</script>
22+
23+
<style scoped>
24+
.notification-container {
25+
position: fixed;
26+
bottom: 0;
27+
right: 0;
28+
padding-right: 40px;
29+
}
30+
</style>

0 commit comments

Comments
 (0)