]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
docs: code example on 'Fetching Before Navigation' with a better context (#1538)
authorMauricio Matias C <mcm.crw@gmail.com>
Tue, 30 Aug 2022 15:01:40 +0000 (11:01 -0400)
committerGitHub <noreply@github.com>
Tue, 30 Aug 2022 15:01:40 +0000 (17:01 +0200)
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
packages/docs/guide/advanced/data-fetching.md

index 8a3882d1062bf1a95d021ab231ea25b154e83919..c372f23709ba7168f7ac04c080d9443ffae31ae6 100644 (file)
@@ -83,6 +83,7 @@ export default {
   },
   beforeRouteEnter(to, from, next) {
     getPost(to.params.id, (err, post) => {
+      // `setData` is a method defined below
       next(vm => vm.setData(err, post))
     })
   },
@@ -96,6 +97,15 @@ export default {
       this.error = error.toString()
     }
   },
+  methods: {
+    setData(error, post) {
+      if (error) {
+        this.error = error
+      } else {
+        this.post = post
+      }
+    }
+  }
 }
 ```