File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change 7
7
{{ post.title }}
8
8
</button >
9
9
10
- {{ store.state.postId }}
10
+ {{ store.state.post }}
11
11
</template >
12
12
13
13
<script >
@@ -17,11 +17,11 @@ export default {
17
17
setup () {
18
18
const posts = [
19
19
{
20
- id: ' 1 ' ,
20
+ id: 1 ,
21
21
title: ' Post 1' ,
22
22
},
23
23
{
24
- id: ' 2 ' ,
24
+ id: 2 ,
25
25
title: ' Post 2' ,
26
26
},
27
27
]
Original file line number Diff line number Diff line change 1
1
import { createStore } from 'vuex'
2
+ import { testPosts } from '../microblog/testPosts.js'
2
3
3
4
const delay = ( ) => new Promise ( res => {
4
5
setTimeout ( res , 1000 )
@@ -7,20 +8,21 @@ const delay = () => new Promise(res => {
7
8
export const store = createStore ( {
8
9
state ( ) {
9
10
return {
10
- postId : null
11
+ post : null
11
12
}
12
13
} ,
13
14
14
15
mutations : {
15
- setPostId ( state , id ) {
16
- state . postId = id
16
+ setPostData ( state , post ) {
17
+ state . post = post
17
18
}
18
19
} ,
19
20
20
21
actions : {
21
- async fetchPostData ( ) {
22
+ async fetchPostData ( ctx , id ) {
22
23
await delay ( )
23
- console . log ( 'LOG' )
24
+ const post = testPosts . find ( x => x . id === id )
25
+ ctx . commit ( 'setPostData' , post )
24
26
}
25
27
}
26
28
} )
You can’t perform that action at this time.
0 commit comments