From 0b073d4caeb6dbd292f89546434fb3b2b34fa168 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Sat, 8 Aug 2020 11:14:43 +0200 Subject: [PATCH] docs: race condition in example Close #2691 --- docs/guide/advanced/data-fetching.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/guide/advanced/data-fetching.md b/docs/guide/advanced/data-fetching.md index b8559c291..bde314f66 100644 --- a/docs/guide/advanced/data-fetching.md +++ b/docs/guide/advanced/data-fetching.md @@ -55,8 +55,11 @@ export default { fetchData () { this.error = this.post = null this.loading = true + const fetchedId = this.$route.params.id // replace `getPost` with your data fetching util / API wrapper - getPost(this.$route.params.id, (err, post) => { + getPost(fetchedId, (err, post) => { + // make sure this request is the last one we did, discard otherwise + if (this.$route.params.id !== fetchedId) return this.loading = false if (err) { this.error = err.toString()