Vue and Vue router. What is the best option to connect value from a get request, with parameter in Vue Router? I want this.id to be replaced by a value from the api request.
const User = {
data() {
return {
loading: false,
name: null
}
},
created() {
this.fetchData()
this.$router.push({ path: /user/${this.id} })
},
watch: {
$route: "fetchData"
},
methods: {
fetchData() {
this.error = this.name = null
this.loading = true
fetch(`https://.../`, (err, post) => {
if (this.$route.params.id !== id) return
this.loading = false
if (err) {
this.error = err.toString()
} else {
this.post = post
}
})
}
}
}