Single Page Applications Chapter 15
Then, assign our Vue root instance to it:
vm = new Vue({
router,
el: '#app',
data: {
showError: false
}
})
We also added the showError variable to the data option.
The last thing to do is actually manage the error on the retrieval of our data, before
displaying the bio information.
Add the highlighted code to the beforeRouteEnter hook:
beforeRouteEnter (to, from, next) {
axios.post('http://example.com/', {
"type": "object",
"properties": {
"name": {
"type": "string",
"ipsum": "name"
},
"phone": {
"type": "string",
"format": "phone"
}
}
}).then(response => {
next(vm => {
vm.name = response.data.name
vm.phone = response.data.phone
})
}).catch(error => {
vm.showError = true
next(false)
})
}