]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
docs(zh): additions `setData` method (#2008)
authorSatrong <satrong@users.noreply.github.com>
Fri, 15 Dec 2023 07:09:59 +0000 (15:09 +0800)
committerGitHub <noreply@github.com>
Fri, 15 Dec 2023 07:09:59 +0000 (08:09 +0100)
packages/docs/zh/guide/advanced/data-fetching.md

index e060fcfb7b4db9d2e811e7bc70d8f249c332a428..521a6396f504ec58d0db8c82dd6ca35eea87dc53 100644 (file)
@@ -82,6 +82,7 @@ export default {
   },
   beforeRouteEnter(to, from, next) {
     getPost(to.params.id, (err, post) => {
+      // `setData` 方法定义在下面的代码中
       next(vm => vm.setData(err, post))
     })
   },
@@ -95,6 +96,15 @@ export default {
       this.error = error.toString()
     }
   },
+  methods: {
+    setData(error, post) {
+      if (error) {
+        this.error = error
+      } else {
+        this.post = post
+      }
+    }
+  }
 }
 ```