Skip to content

Commit 779401b

Browse files
committed
Exercise 4.4
1 parent f748e6c commit 779401b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

4-state-management/4.4-mutations.html

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script src="../node_modules/vue/dist/vue.js"></script>
22

3-
<div>
3+
<div id="app">
44
<counter></counter>
55
<counter></counter>
66
<counter></counter>
@@ -9,7 +9,19 @@
99

1010
<script>
1111
function createStore ({ state, mutations }) {
12-
// Implement this!
12+
return new Vue({
13+
data: {
14+
state
15+
},
16+
methods: {
17+
commit (mutation) {
18+
if (!mutations.hasOwnProperty(mutation)) {
19+
throw new Error('Unknown mutation')
20+
}
21+
mutations[mutation](state)
22+
}
23+
}
24+
})
1325
}
1426

1527
const store = createStore({

0 commit comments

Comments
 (0)