Skip to content

Commit ec9a84a

Browse files
committed
update
1 parent 0126398 commit ec9a84a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

vuex/App.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{{ post.title }}
88
</button>
99

10-
{{ store.state.postId }}
10+
{{ store.state.post }}
1111
</template>
1212

1313
<script>
@@ -17,11 +17,11 @@ export default {
1717
setup() {
1818
const posts = [
1919
{
20-
id: '1',
20+
id: 1,
2121
title: 'Post 1',
2222
},
2323
{
24-
id: '2',
24+
id: 2,
2525
title: 'Post 2',
2626
},
2727
]

vuex/store.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createStore } from 'vuex'
2+
import { testPosts } from '../microblog/testPosts.js'
23

34
const delay = () => new Promise(res => {
45
setTimeout(res, 1000)
@@ -7,20 +8,21 @@ const delay = () => new Promise(res => {
78
export const store = createStore({
89
state() {
910
return {
10-
postId: null
11+
post: null
1112
}
1213
},
1314

1415
mutations: {
15-
setPostId(state, id) {
16-
state.postId = id
16+
setPostData(state, post) {
17+
state.post = post
1718
}
1819
},
1920

2021
actions: {
21-
async fetchPostData() {
22+
async fetchPostData(ctx, id) {
2223
await delay()
23-
console.log('LOG')
24+
const post = testPosts.find(x => x.id === id)
25+
ctx.commit('setPostData', post)
2426
}
2527
}
2628
})

0 commit comments

Comments
 (0)