Skip to content

Commit 61193fc

Browse files
committed
79
1 parent 23a1c4d commit 61193fc

File tree

8 files changed

+96
-60
lines changed

8 files changed

+96
-60
lines changed

db.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,30 @@
140140
"completed": false,
141141
"body": "asdfasdf",
142142
"id": 31
143+
},
144+
{
145+
"subject": "asdf",
146+
"completed": false,
147+
"body": "asdf",
148+
"id": 32
149+
},
150+
{
151+
"subject": "asdf",
152+
"completed": false,
153+
"body": "asdf",
154+
"id": 33
155+
},
156+
{
157+
"subject": "adsf",
158+
"completed": false,
159+
"body": "asdf",
160+
"id": 34
161+
},
162+
{
163+
"subject": "adsf",
164+
"completed": false,
165+
"body": "asdf",
166+
"id": 35
143167
}
144168
]
145169
}

src/App.vue

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
<div class="container">
1616
<router-view/>
1717
</div>
18-
<Toast
19-
v-if="showToast"
20-
:message="toastMessage"
21-
:type="toastAlertType"
22-
/>
18+
<transition name="slide">
19+
<Toast
20+
v-if="showToast"
21+
:message="toastMessage"
22+
:type="toastAlertType"
23+
/>
24+
</transition>
2325
</template>
2426

2527
<script>
@@ -50,5 +52,21 @@ export default {
5052
}
5153
</script>
5254

53-
<style>
55+
<style scoped>
56+
.slide-enter-active,
57+
.slide-leave-active {
58+
transition: all 0.5s ease;
59+
}
60+
61+
.slide-enter-from,
62+
.slide-leave-to {
63+
opacity: 0;
64+
transform: translateY(-30px);
65+
}
66+
67+
.slide-enter-to,
68+
.slide-leave-from {
69+
opacity: 1;
70+
transform: translateY(0px);
71+
}
5472
</style>

src/components/TodoForm.vue

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,18 @@
5151
Cancel
5252
</button>
5353
</form>
54-
<transition name="fade">
55-
<Toast
56-
v-if="showToast"
57-
:message="toastMessage"
58-
:type="toastAlertType"
59-
/>
60-
</transition>
6154
</template>
6255

6356
<script>
6457
import { useRoute, useRouter } from 'vue-router';
6558
import axios from '@/axios';
6659
import { ref, computed } from 'vue';
6760
import _ from 'lodash';
68-
import Toast from '@/components/Toast.vue';
6961
import { useToast } from '@/composables/toast';
7062
import Input from '@/components/Input.vue';
7163
7264
export default {
7365
components: {
74-
Toast,
7566
Input
7667
},
7768
props: {

src/composables/toast.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { useStore } from 'vuex';
33

44
export const useToast = () => {
55
const store = useStore();
6-
const toastMessage = computed(() => store.getters.toastMessageWithSmile);
7-
const toastAlertType = computed(() => store.state.toastAlertType);
8-
const showToast = computed(() => store.state.showToast);
6+
const toastMessage = computed(() => store.getters['toast/toastMessageWithSmile']);
7+
const toastAlertType = computed(() => store.state.toast.toastAlertType);
8+
const showToast = computed(() => store.state.toast.showToast);
99

1010
const triggerToast = (message, type = 'success') => {
11-
store.dispatch('triggerToast', message, type);
11+
store.dispatch('toast/triggerToast', message, type);
1212
}
1313

1414
return {

src/pages/todos/index.vue

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,18 @@
4949
</ul>
5050
</nav>
5151
</div>
52-
<Toast
53-
v-if="showToast"
54-
:message="toastMessage"
55-
:type="toastAlertType"
56-
/>
5752
</template>
5853

5954
<script>
6055
import { ref, computed, watch } from 'vue';
6156
import TodoList from '@/components/TodoList.vue';
6257
import axios from '@/axios';
63-
import Toast from '@/components/Toast.vue';
6458
import { useToast } from '@/composables/toast';
6559
import {useRouter} from 'vue-router';
6660
6761
export default {
6862
components: {
6963
TodoList,
70-
Toast,
7164
},
7265
setup() {
7366
const router = useRouter();

src/store/index.js

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,6 @@
11
import { createStore } from 'vuex';
2+
import modules from './modules';
23

34
export default createStore({
4-
state: {
5-
toastMessage: '',
6-
toastAlertType: '',
7-
showToast: false,
8-
},
9-
mutations: {
10-
UPDATE_TOAST_MESSAGE (state, payload) {
11-
state.toastMessage = payload;
12-
},
13-
UPDATE_TOAST_ALERT_TYPE (state, payload) {
14-
state.toastAlertType = payload;
15-
},
16-
UPDATE_TOAST_STATUS (state, payload) {
17-
state.showToast = payload;
18-
}
19-
},
20-
actions: {
21-
triggerToast({ commit }, message, type = 'success') {
22-
commit('UPDATE_TOAST_MESSAGE', message)
23-
commit('UPDATE_TOAST_ALERT_TYPE', type)
24-
commit('UPDATE_TOAST_STATUS', true)
25-
26-
setTimeout(() => {
27-
commit('UPDATE_TOAST_MESSAGE', '')
28-
commit('UPDATE_TOAST_ALERT_TYPE', '')
29-
commit('UPDATE_TOAST_STATUS', false)
30-
}, 5000)
31-
}
32-
},
33-
getters: {
34-
toastMessageWithSmile (state) {
35-
return state.toastMessage + '^_^';
36-
}
37-
}
5+
modules
386
});

src/store/modules/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import toast from './toast';
2+
3+
export default {
4+
toast
5+
}

src/store/modules/toast/index.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export default {
2+
namespaced: true,
3+
state: {
4+
toastMessage: '',
5+
toastAlertType: '',
6+
showToast: false,
7+
},
8+
mutations: {
9+
UPDATE_TOAST_MESSAGE (state, payload) {
10+
state.toastMessage = payload;
11+
},
12+
UPDATE_TOAST_ALERT_TYPE (state, payload) {
13+
state.toastAlertType = payload;
14+
},
15+
UPDATE_TOAST_STATUS (state, payload) {
16+
state.showToast = payload;
17+
}
18+
},
19+
actions: {
20+
triggerToast({ commit }, message, type = 'success') {
21+
commit('UPDATE_TOAST_MESSAGE', message)
22+
commit('UPDATE_TOAST_ALERT_TYPE', type)
23+
commit('UPDATE_TOAST_STATUS', true)
24+
25+
setTimeout(() => {
26+
commit('UPDATE_TOAST_MESSAGE', '')
27+
commit('UPDATE_TOAST_ALERT_TYPE', '')
28+
commit('UPDATE_TOAST_STATUS', false)
29+
}, 5000)
30+
}
31+
},
32+
getters: {
33+
toastMessageWithSmile (state) {
34+
return state.toastMessage + '^_^';
35+
}
36+
},
37+
}

0 commit comments

Comments
 (0)