Issue with Vue 3 component not updating following vue-router invocation

I am currently working on developing a todo app using ionic-vue with vue 3. In my Lists.vue component, I have set up an overview where users can click on different lists to load tasks specific to each list. However, I am facing an issue where the same data is being displayed every time a list is clicked. It seems like the component is being reused but not properly re-rendered or updated.

I have attempted various solutions to address this issue, such as implementing a watch on the changing ref, but it did not yield the desired result. Even adding a :key to the router-link did not resolve the problem.

Below is a snippet of my Lists.vue component:

 // code snippet here...

In addition, I also have another component called Index.vue which displays individual list details:

 // code snippet here...

Furthermore, I have created a composable function to fetch data for the app:

 // code snippet here...

If anyone has any suggestions or insights on how to fix the issue I am facing, I would greatly appreciate your help. Thank you in advance for your valuable input!

Please note that I may not be able to respond quickly due to certain circumstances, but rest assured I will get back to your answers as soon as possible :)

Answer №1

Finally cracked the code to my issue! Utilizing watchEffect on the loadValue method was the key to retrieving data from the database effectively. It appears that Vue prioritizes reusing components over rerendering them for better efficiency, a fact I discovered after delving into online research.

Although the route params were getting updated, the component's key remained stagnant.

The setup function within Index.vue (the task list)

 setup() {
        const router = useRouter()
        const route = useRoute()
        const { loadValue } = getValue()
        const category = ref()

        // Redirect back to lists when clicking on close icon.
        const redirectBack = () => {
            return router.push({name: 'Lists'})
        }
       
        // Fetching data of a specific category.
        const getCategory = () => {
            loadValue('categories', route.params.categoryId).then(data => {
                category.value = data
            })
        }

        watchEffect(() => {
            getCategory()
        })

        return {
            closeOutline,
            redirectBack,
            category,
        }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with redirecting to another link in Angular routing

After numerous attempts, I finally managed to configure the adviceRouterModule correctly. Despite extensive research and Google searches, I couldn't quite crack it. Here is the configuration for my AdviceRoutingModule: const adviceRouters: Routes = ...

Make sure that only one viewmodel property has insertMessages set to false in Knockout.js

Is it achievable to customize the insertMessages property to false for a specific view model property using Knockout.js instead of setting it globally using ko.validation.init({ insertMessages: false });? I am attempting to set insertMessages to false only ...

What is the correct way to use "DELETE" and "BACKSPACE" in a condition statement?

Attempting to prevent the deletion of input values when the length is 2 or lower, but my if statement doesn't seem quite right. $(document).ready(function() { $('#mobile').val("09"); // Set initial value to "09" $('#mobile&ap ...

Generate a Vue project using the vue-cli-service build command, but be sure to include the necessary period in

After completing my Vue project, I encountered an issue when running the script 'npm run build' (vue-cli-service build). The output files were generated as expected, but the paths to all js and css files in the index.html file were incorrect. For ...

What is the most efficient way to transfer an item from one component to another in React

When I try to assign one object into another, it does not get added as a key in the new object. var check = Object.assign(product, cart_item); If you look at the image below https://i.sstatic.net/jf2xK.png I would appreciate any insights on how can I add ...

Tips on implementing VueStripe in a vue2 Project

I recently integrated Vue Stripe into my vue2 Project and encountered 2 similar errors in my code : Property 'redirectToCheckout' does not exist on type 'Vue | Element | (Vue | Element)[]'. Property 'publishableKey' does ...

Disable the default animation

Is there a way to disable the default animation of the Select label in my code snippet below? export default function TicketProfile(props: any) { return ( <Container> <FormControl sx={{ ml: 1, mr: 1, minWidth: 220 }}> <Inp ...

Combining arrays in a nested array with the help of Javascript/Vue.Js

I am faced with a JSON array containing 3 arrays that I need to merge into one array after fetching the JSON data. Although I attempted to do so using Vue.JS, the resulting array appears to be empty. MY FIRST ATTEMPT this.items = items; MY LATEST ATTEMP ...

Executing the outer function from within the inner function of a different outer function

Imagine this scenario: function firstFunction() { console.log("This is the first function") } secondFunction() { thirdFunction() { //call firstFunction inside thirdFunction } } What is the way to invoke firstFunction from thirdFunction? ...

Is there a problem with the props being passed? Can someone verify this

Blockquote Having trouble passing props, Parent component: props: { data: { type: Object as PropType<FormatOrderItem>, default: () => {} } I'm facing an issue when trying to pass props from the parent component to the ch ...

An elusive static image file goes unseen within the realm of node.js/express

I am encountering an issue with serving static files in Express on Node.js. When I request a .css file from the server, everything works fine. However, if I try to load an image such as a jpg or png, it just shows a blank white page without any error messa ...

Node js overlooking non-packaged middleware

I encountered an issue with middleware that used to be included in NODE.js but is no longer bundled. I followed the instructions provided here: Node js Error: Most middleware (like session) is no longer bundled with Express and must be installed separatel ...

Leveraging retrieved API data to generate numerous components

Hey there! I'm new to JavaScript and I'm working on creating a todo list with fake ToDos from jsonplaceholder using Fetch. My goal is to fetch five different ToDos and display them in separate list items within my list. However, I'm encounte ...

When sending API data back to Vue from Express, the response is coming back as an empty

I am encountering an issue with my express app where I am trying to send data back from a third-party API to my front-end application. Despite being able to see the content in my express API, I am not receiving any results on the front end. Any suggestions ...

extracting a characteristic from one entity and transferring it to another entity

Hey there, I have a tricky problem to solve. I am trying to extract a value from an array that's inside an object. $scope.document=[] $scope.accounts=[{name:"123"},{name:"124"},{name:"125"}] My goal is to take the first array element and append it ...

Troubleshooting: Mongoose Array Object Order Modification Issue

Imagine we have a person named Michael who lists his favoriteFruits as [ { name: 'Apple'}, {name: 'Banana'} ] The challenge at hand is to change the order of his favorite fruits. In other words, we want to transform it from: [ { name ...

Preventing users from inputting the same number more than once

Here are a series of text input fields pertaining to a single question: <input type="text" name="{{ $answer->id }}" value="" style="width:20px; text-align:center" maxlength="1" oninput="this.value=this.value.replace(/[^0-5]/g,'');" /> & ...

What is the reason javascript struggles to locate and replace strings with spaces in a URL?

Let me begin by sharing the code I'm currently working on so that you can easily follow my explanations. Apologies for the French language used, as this website is being developed for a French-speaking school. I have eliminated irrelevant sections fro ...

submitting numerous forms using AJAX

On my webpage, each entry in the database has its own form that saves data upon pressing the enter key. However, I am facing an issue where only one specific form is being saved and not all of them. How can I differentiate between the forms and ensure that ...

Using Bootstrap Collapse with EJS Iteration

I am having trouble with this specific section of my ejs file where the collapse feature is not functioning correctly. Can someone please assist me? <% for(var i=0;i<data.length;i++){%> <div id="content"> <p><%=data[i].w ...