Skip to content

Commit 1cc73b3

Browse files
committed
add handleClick event on notification item component
1 parent 75c3393 commit 1cc73b3

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export default {
1717
vm.options = options
1818
}
1919

20-
Vue.prototype.$notification = (title, body, dateTime, icon = null) => {
21-
vm.addNewNotification(Math.random(), title, body, dateTime, icon)
20+
// eslint-disable-next-line no-unused-vars
21+
Vue.prototype.$notification = (title, body, dateTime, icon = null, handleClick) => {
22+
vm.addNewNotification(Math.random(), title, body, dateTime, icon, handleClick)
2223
}
2324
}
2425
}

src/Notification.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<div :class="`notification ${options.position}`">
33
<NotificationItem
4+
:callback="handleClicked"
45
:key="key"
56
:duration="options.duration"
67
v-for="(notification, key) in notifications"
@@ -19,8 +20,9 @@ export default {
1920
return {
2021
options: {
2122
position: 'notification-top-right',
22-
duration: 2500,
23-
}
23+
duration: 2500
24+
},
25+
handleClick: null,
2426
}
2527
},
2628
computed: {
@@ -29,7 +31,11 @@ export default {
2931
})
3032
},
3133
methods: {
32-
addNewNotification(id, title, body, dateTime, icon) {
34+
handleClicked () {
35+
this.handleClick()
36+
},
37+
addNewNotification(id, title, body, dateTime, icon, handleClick) {
38+
this.handleClick = handleClick
3339
this.$store.commit('notification/add', {
3440
id: id,
3541
title: title,

src/components/NotificationItem.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="notification-item">
2+
<div class="notification-item" @click="handleClick">
33
<div class="notification-icon"
44
:class="{'no-circle' : notification.icon === null}"
55
:style="`background-image: url(${icon});`">
@@ -32,6 +32,9 @@ export default {
3232
},
3333
duration: {
3434
type: Number,
35+
},
36+
callback: {
37+
type: Function
3538
}
3639
},
3740
computed: {
@@ -44,6 +47,11 @@ export default {
4447
}
4548
},
4649
methods: {
50+
handleClick () {
51+
if (this.callback) {
52+
this.callback()
53+
}
54+
},
4755
async removeNotification() {
4856
this.$store.commit('notification/remove', this.notification)
4957
}

0 commit comments

Comments
 (0)