Skip to content

Commit 23a1c4d

Browse files
committed
78
1 parent f8677b4 commit 23a1c4d

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

db.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@
116116
"completed": false,
117117
"body": "df",
118118
"id": 27
119+
},
120+
{
121+
"subject": "asdf",
122+
"completed": false,
123+
"body": "asdf",
124+
"id": 28
125+
},
126+
{
127+
"subject": "asdf",
128+
"completed": false,
129+
"body": "asdfasdf",
130+
"id": 29
131+
},
132+
{
133+
"subject": "e",
134+
"completed": false,
135+
"body": "f",
136+
"id": 30
137+
},
138+
{
139+
"subject": "asdf",
140+
"completed": false,
141+
"body": "asdfasdf",
142+
"id": 31
119143
}
120144
]
121145
}

src/composables/toast.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
1-
import { computed, onUnmounted } from 'vue';
1+
import { computed } from 'vue';
22
import { useStore } from 'vuex';
33

44
export const useToast = () => {
55
const store = useStore();
6-
const toastMessage = computed(() => store.state.toastMessage);
6+
const toastMessage = computed(() => store.getters.toastMessageWithSmile);
77
const toastAlertType = computed(() => store.state.toastAlertType);
88
const showToast = computed(() => store.state.showToast);
9-
const timeout = computed(() => store.state.timeout);
9+
1010
const triggerToast = (message, type = 'success') => {
11-
toastMessage.value = message;
12-
toastAlertType.value = type;
13-
showToast.value = true;
14-
timeout.value = setTimeout(() => {
15-
toastMessage.value = '';
16-
toastAlertType.value = '';
17-
showToast.value = false;
18-
}, 5000)
19-
}
11+
store.dispatch('triggerToast', message, type);
12+
}
2013

21-
onUnmounted(() => {
22-
clearTimeout(timeout.value);
23-
})
2414
return {
2515
toastMessage,
2616
toastAlertType,

src/store/index.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export default createStore({
55
toastMessage: '',
66
toastAlertType: '',
77
showToast: false,
8-
timeout: null
98
},
109
mutations: {
1110
UPDATE_TOAST_MESSAGE (state, payload) {
@@ -16,30 +15,24 @@ export default createStore({
1615
},
1716
UPDATE_TOAST_STATUS (state, payload) {
1817
state.showToast = payload;
19-
},
20-
UPDATE_TOAST_TIMEOUT (state, payload) {
21-
state.timeout = payload;
2218
}
2319
},
2420
actions: {
2521
triggerToast({ commit }, message, type = 'success') {
26-
// toastMessage.value = message;
2722
commit('UPDATE_TOAST_MESSAGE', message)
28-
// toastAlertType.value = type;
2923
commit('UPDATE_TOAST_ALERT_TYPE', type)
30-
// showToast.value = true;
3124
commit('UPDATE_TOAST_STATUS', true)
3225

33-
const timeout = setTimeout(() => {
34-
// toastMessage.value = '';
26+
setTimeout(() => {
3527
commit('UPDATE_TOAST_MESSAGE', '')
36-
// toastAlertType.value = '';
3728
commit('UPDATE_TOAST_ALERT_TYPE', '')
38-
// showToast.value = false;
3929
commit('UPDATE_TOAST_STATUS', false)
4030
}, 5000)
41-
42-
commit('UPDATE_TOAST_TIMEOUT', timeout);
4331
}
32+
},
33+
getters: {
34+
toastMessageWithSmile (state) {
35+
return state.toastMessage + '^_^';
36+
}
4437
}
4538
});

0 commit comments

Comments
 (0)