Skip to content
Advertisement

Vue 3 component not updating after call from vue-router

I want to build a todo app with ionic-vue. It currently uses vue 3. I have this overview (called Lists.vue) where it is possible to click on multiple lists (where tasks should be loaded per list). However, everytime when I click on a list, the same data appears! It is as if the component is being reused but not re rendered/ updated.

I have tried all kinds of solutions. One of them was to apply a watch on the ref that is being changed, however, it does not matter, the end result stays the same. Also tried to give :key to router-link, still does not work.

My Lists.vue

JavaScript

My list called Index.vue (maybe I should just call it list.vue or something…)

JavaScript

My composable function:

JavaScript

If someone knows any possible solutions, or what I’m possibly doing wrong, please help! All solutions are very appreciated.

PS: Due to circumstances, I am currently not able to reply very fast, but I assure you that I will reply to your answers 🙂

Advertisement

Answer

Found the answer to my problem! I had to use watchEffect on the loadValue method in order to recall the data from the database. It would seem that Vue (after some research on the internet) wants to reuse components instead of rerendering them, which is more efficient.

The route params were being updated but the key of the component was not, however.

The setup function on Index.vue (the list of tasks)

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement