Я пытаюсь получить данные из API, используя beforeEnter()
route guard, но получаю сообщение об ошибке:
Missing required prop: "rides"
Вот мой код.
router.js
{
path: '/',
name: 'home',
component: () => import('./components/main.vue'),
props: true,
beforeEnter(to, from, next) {
store.dispatch('ride/fetchRides').then(rides => {
to.params.rides = rides
next()
})
}
}
actions.js
fetchRides({ commit, dispatch }) {
return statistcsService.ridesForCurrentWeek()
.then(response => {
commit('SET_RIDES', response.data)
return response.data
})
.catch(error => {
const notification = {
type: 'danger',
message: 'There was a problem fetching your rides'
}
dispatch('notification/add', notification, { root: true })
throw error
})
}
Index.vue
<script>
export default {
props: {
rides: {
type: Array,
required: true
}
}
...
}
</script>
Чего мне не хватает? В компоненте установлена опора, поэтому я не уверен, почему он плачет.
Я подтвердил, что на 100% я получаю данные из ответа API.