Skip to content

Commit 8b59f86

Browse files
authored
docs(zh): additions setData method (#2008)
1 parent 3c91f0f commit 8b59f86

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/docs/zh/guide/advanced/data-fetching.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export default {
8282
},
8383
beforeRouteEnter(to, from, next) {
8484
getPost(to.params.id, (err, post) => {
85+
// `setData` 方法定义在下面的代码中
8586
next(vm => vm.setData(err, post))
8687
})
8788
},
@@ -95,6 +96,15 @@ export default {
9596
this.error = error.toString()
9697
}
9798
},
99+
methods: {
100+
setData(error, post) {
101+
if (error) {
102+
this.error = error
103+
} else {
104+
this.post = post
105+
}
106+
}
107+
}
98108
}
99109
```
100110

0 commit comments

Comments
 (0)