What steps should I take to solve this wheel-related issue in my Vue 3 application?

I have been developing a Single Page Application (SPA) using Vue 3, TypeScript, and The Movie Database (TMDB).

Currently, I am tackling the implementation of a search feature and I've encountered a bug.

The "search-box" component is located in src\components\TopBar.vue:

<template>
   <form class="search_form w-100 mx-auto mt-2 mt-md-0">
    <div class="input-group">
      <input v-on:keyup="debounceMovieSearch" v-model="searchTerm" class="form-control search-box" type="text" placeholder="Search movies...">
      <div class="input-group-append">
        <button class="btn" type="button">
          <font-awesome-icon :icon="['fas', 'search']" />
        </button>
      </div>
    </div>
    
    <div v-if="isSearch" @click="isSearch = false" class="search-results shadow-sm">
      <div v-if="this.movies.length">
        <router-link v-for="movie in movies.slice(0, 10)" :key="movie.id" :to="`/movie/${movie.id}`">
          <SearchItem :movie="movie" />
        </router-link>
      </div>
      
      <div v-else>
        <p class="m-0 p-2 text-center">No movies found for this search</p>
      </div>
    </div>
  </form>
</template>
.
.
.

Stackblitz Preview

You can take a look at the interactive demo on Stackblitz.

. . [Your problem statement goes here] . .

Inquiries

  1. Can you identify any mistakes in my code implementation?
  2. How would you suggest resolving this issue effectively?

Answer №1

The issue lies not with the router, but with how the movie details are rendered after the user is redirected to a different movie/id. Currently, the movie details in MovieDetails.vue are only rendered using the mounted() function, which is called only once in the component's lifecycle. To address this, you need to add a watch to monitor redirection changes and update the component accordingly. In MovieDetails.vue, include the following code:

watch: {
    '$route.params.id'(newId) {
      this.getMovieDetails();
      this.getMovieTrailers();
      this.getMovieCast();
    }
}

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

Adjust the menu scrollbar position to the right or limit scrolling to within the menu area

$(function() { "use strict"; $(".navbar-toggler").on("click", function() { $(".navbar-toggler").toggleClass("collapsed"); $(".offcanvas-collapse").toggleClass("open"); let menuposition = $("#toggler").offset().left + $("#toggler").width() + ...

Ajax request received no data from API

I have been facing an issue with my code where I am posting an email on an API URL using an HTML form and PHP code with an Ajax call. However, the response I am getting is empty. I need to display this response on the same page below the form. I am sharing ...

What methods can be used to accomplish this effect using CSS and/or Javascript?

Is there a way to achieve the desired effect using just a single line of text and CSS, instead of multiple heading tags and a CSS class like shown in the image below? Current Code : <h2 class="heading">Hi guys, How can i achieve this effect using j ...

Extract specific data points from external API responses on a webpage crafted in HTML

I require assistance on how to extract individual values from an HTML page. I received a response from the PAYU payment gateway team in HTML format, but I need to retrieve specific attribute values related to the transaction details. Below is the response ...

"Encountering a problem with object transformation in Three.js using

I'm attempting to adjust both the height (Y) and vertical position of a cube simultaneously in order to keep its base on the same X-Z plane after scaling. The visual display seems to be working correctly, but the actual behavior is not meeting my expe ...

JavaScript function executes before receiving AJAX response

Within my code, there is an AJAX function named flagIt() that gets triggered by another function called validateForm() upon submission. The validateForm() function is responsible for form validation. function validateForm(){ var error = ""; //perf ...

Vue fails to retrieve the accurate value of the option, instead displaying the text

Just started using Vue.js through CDN. Currently working with a select element: <select @change="setValue($event.target.value)"> <option>Pick</option> <option val="1">First Choice</option> <opt ...

The Mobile Side Menu Is Not Scrollable

I've encountered an issue with the side menu on my website. While it works perfectly fine on PC, it refuses to scroll on mobile devices. I've tested it on both my iPhone 5 and iPad, but no luck. Additionally, the toggle button isn't function ...

Exploring the capabilities of AWS Cognito with Vue.js

I recently created a backend API using Expressjs hosted on AWS EC2. I also developed a frontend application in Vuejs that interacts with the Express API. My next step is to implement user Authorization for sign-ins, and after some research, I've deci ...

Is it possible to serialize the entirety of a website's Javascript state, including Closure/Hidden scopes?

My goal is to capture a "snapshot" of a webpage while maintaining its interactive functionality, allowing all Javascript states to be saved and restored. An example scenario where this would be beneficial is when a webpage contains script that utilizes glo ...

VUEX doesn't recognize a mutation that has been defined

I recently started using VUEX and everything was going smoothly until I introduced a new mutation called "shipping". Now, every time I try to commit it, I get an error message saying: unknown mutation type: shipping. It's puzzling because all my previ ...

Encountering the message "Error: Unable to access undefined properties (reading 'username')" while making my POST request

My POST request isn't functioning correctly and it's failing to update. The specific error message I'm encountering is: TypeError: Cannot read properties of undefined (reading 'username') app.post('/create-user', functio ...

Error in Angular unit testing: Unable to access the 'subscribe' property as it is undefined

Currently, I am working on a starter kit template that includes authentication and an example with CRUD operations. You can find the code here: https://github.com/fransyozef/basic-login-angular Although I am new to unit testing, I am trying to set up test ...

When implementing dynatable with Meteor, the outcomes may vary between the demonstration in a fiddle and the actual application

Here is the fiddle I created for this question: https://jsfiddle.net/ereday/82wzwem8/2/ In the fiddle, you'll notice that the table header has a green background. Now, let me share the code snippet from my meteor project: simple-todos.html <head ...

Automatically Refresh a Div Element Every 5 Seconds Using jQuery's setInterval() Function

My goal is to refresh the left div every 5 seconds using $.ajax to get JSON data and display 4 random elements in that div. However, even though the left div block refreshes, the content remains the same with the same images always showing. view image desc ...

What could be the reason for my code generating the error [$http:badreq]?

I'm currently attempting to retrieve JSON data from a certain URL and am having trouble getting it to work. Despite going through the Angular documentation and other resources, I still can't pinpoint the issue due to my limited experience with An ...

What steps should I take to set up my Nuxt frontend app so that it recognizes the baseUrl of the Strapi backend?

I have been following these two tutorials: Creating a Deliveroo clone with Nuxt, Apollo, and Strapi Building a blog using Nuxt, Strapi, and Apollo Despite multiple attempts to understand the process by reading Strapi's documentation, I am strugglin ...

Creating TypeScript declaration file for exporting JavaScript function

I'm a beginner with TypeScript and I want to learn how to create a declaration file for a custom JavaScript function. I attempted to do this, however, I encountered an error stating "Could not find a declaration file for module './main'." Ad ...

Input the date manually using the keyboard

I am currently utilizing the rc calendar package available at https://www.npmjs.com/package/rc-calendar When attempting to change the year from 2019 to 2018 by removing the "9," it works as expected. However, when trying to delete the entire date of 1/15/2 ...

Is there a solution to resolving the type error that I am unable to identify?

I am attempting to implement a custom cursor feature in Vue 3, but unfortunately my code is not functioning as expected. Below you can find the code snippet I have been working on: <template> <div id="cursor" :style="cursorPoi ...