Leverage the power of v-model props in your Vue 3 component to efficiently retrieve API breakpoints

I am currently working on integrating the API breakpoints in my child component.
These components are designed for my football web application.
The breakpoints are sourced from: api-football

My challenge lies in passing multiple prop values into a component.
During debugging, I noticed that only the second prop (league) is being read in the parent component.

Encountered Errors:

If you have some spare time, feel free to provide a code review. I am currently learning Vue.

Teams.vue (parent):

<template>
  <main id="Home-page">
    <UserPanel/>

    <Transition name="bounce">
      <h1 v-if="headerShow" class="welcome-header">
        Team statistics
      </h1>
    </Transition>

    ...
 
      </div>
    </div>
  </main>
</template>

...
 
      })
    },
  },
  watch: {
    selectedLeague: function (value) {
      
      this.teams.length = 0;
    
          }
        }).catch(function (error) {
          console.error(error);
        });
    },
    selectedTeam: function (value) {
      console.log(value)
    }
  },
}
</script>

<style>
   /* styles go here */
</style>

TeamStatistics.vue (child):

<template>
  <div class="popup">

    ...

  }
}
</script>

<style scoped>
   /* styles go here */
</style>

Example response:


    let response = {
      "league": {
        "id": 39,
        "name": "Premier League",
        "country": "England",
        "logo": "https://media.api-sports.io/football/leagues/39.png",
        "flag": "https://media.api-sports.io/flags/gb.svg",
        "season": 2022
      },
      "team": {
        "id": 33,
        "name": "Manchester United",
        "logo": "https://media.api-sports.io/football/teams/33.png"
      },
      "form": "LLWWWWLWDWDWLW",
      ...

Answer №1

To start, eliminate all instances of this in your templates.

How can I send multiple prop values to a component?

If you want to accomplish this dynamically, you can utilize v-bind, like so:

<MyComponent v-bind="componentProps"/>
componentProps() {
    return {
        propA:'foo',
        propB: 'bar'
        ...
    }
}

In this scenario, componentProps can be either a function or computed property where the returned object contains the props as keys.

Moreover,

document.getElementsByClassName('popup')[0].style.visibility = 'hidden';
Avoid doing that. Instead, use v-show with a variable. (docs)

In your TeamStatistics file, you have:

props: {
    data: {
      selectedLeague: String,
      selectedTeam: String
    }
  },

and you are applying v-model with the other props: selectedLeague andselectedTeam. Revise the props declaration in your TeamStatistics.vue like this:

props: ['selectedLeague', 'selectedTeam']

(props docs)

Then you should be able to correctly utilize v-model:selectedLeague. For two-way data binding (which v-model facilitates), you need to emit an event from your TeamStatistics.vue, such as:

$emit('update:selectedLeague',"some-value-here");
$emit('update:selectedTeam',"some-other-value-here");

Refer to this for further information.

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

Insert a character or icon into a :value

I am faced with a situation where I have two input text fields, each being assigned a value from an array stored in a state. The array contains two elements, one for each input field. However, I wish to append a symbol such as % or some additional text at ...

Caution: Updating a component is not possible during the rendering of another component. ReactJS

I am encountering an error in my ReactHooks/Typescript application with a Navigation component that renders a PatientInfo component. The PatientInfo component is conditionally rendered based on the props it receives, determined by a searchbox in another ch ...

Do I require two bot logins for discord.js?

Working on my discord bot, I've been trying to incorporate a script from index.js. Should I also include bot.login at the end of cmdFunctions.js? Here is the content of index.js: const Discord = require('discord.js'); const bot = new Discor ...

Extracting data from an array using Angular

Currently, I am developing an Angular application that involves handling an array structured like the one below. [ { Code: "123", Details:[ { Id: "1", Name: "Gary" }, { ...

Search functionality that dynamically updates results as the user types, thanks

I am currently working on implementing a search feature that can assist users when typing in their search queries. The goal is to use Ajax to dynamically show results as the user types. Currently, the functionality requires the user to hit the search butt ...

Surprising Media Component Found in URL Parameters within the design

Exploring the page structure of my Next.js project: events/[eventId] Within the events directory, I have a layout that is shared between both the main events page and the individual event pages(events/[eventId]). The layout includes a simple video backgro ...

Ways to extract innerHTML content from a loaded element generated by using the .load() method

Check out the code snippet below: template.html : <div id="nav"> Welcome to Space </div> layout.html : <div id="content"> </div> $('#content').load("template.html #nav"); ale ...

Transferring data between various stages of the user interface

As a newcomer to angularJs, I find myself facing an issue with two forms existing in different UI states (URLs) labeled as Step 1 and Step 2. The process requires filling up Step 1 and moving to the next step by clicking the NEXT button, which then leads t ...

Is my React component being rendered twice?

I have created an app component and a test component. Within both components, I have included a console.log statement in the render method. Upon observation, I noticed that the app component is only rendered once, while the test component renders twice. Ad ...

Guide to authenticating Cashfree gateway's webhook signature using JavaScript

I have integrated the Cashfree payments gateway successfully. However, I am unsure how to verify the signature of webhooks. https://i.stack.imgur.com/TxdTx.png This is their recommended approach. Could someone guide me on writing JavaScript code for this ...

Show a modal component from another component in Angular 2

As a newcomer to Angular, I'm working on a modal component that changes from hiding to showing when a button with (click) is clicked. The goal is to integrate this modal into my main component, allowing me to display the modal on top of the main conte ...

Using VueJS to create a dynamic inline template with a v-for loop

I'm having an issue with my in-line template for dropdown menus. When switching between states, the links are becoming jumbled. Here's the code I'm using in the main template: <div> <article v-for="(game, index) in games"& ...

The documentation for Gridsome/Netlify CMS has a flaw that results in Graphql not functioning

My attempts to integrate Gridsome with NetlifyCMS using Gridsome's documentation have been unsuccessful. Below is a snippet of the Netlify config.yml setup: collections: - name: "posts" label: "Posts" folder: "posts" create: true s ...

utilizing the identical characteristics of the parent component

In order for the properties in InputGroup.js to be accessible as this.props in lower-level components like TextInput.js, Checkbox.js, I have created a simple component called InputComponent.js. In this component, I assign this.props to this.prpt so that it ...

Navigate through content easily using the arrow keys on your keyboard with the help of Easy Slider

I'm attempting to modify the Easy Slider in order to enable navigation of the slideshow with the arrow keys on the keyboard. I made adjustments to the javascript's animate function, changing it from: default: t = dir; break; ...to: default: t ...

Tips for efficiently navigating to Vue methods, computeds, and data in VS Code!

I've attempted to utilize the symbol explorer in VSCode (CTRL+P then typing @). It enables me to navigate to methods by jumping to data, but I'm unable to jump to regular properties such as "computed:" or "methods:"? It would come in handy when ...

Creating HTML form input fields for reading and writing an XML file

Currently working on constructing an HTML form containing input fields to read and modify data from an XML file. The initial task involves loading values into the input fields upon page load, but unfortunately, it is not functioning as expected. < ...

Violation of content security policy due to the usage of inline styling in the tawk.to

I have incorporated Tawk.to's chat widget codes into my website to include the chat bubble. The code is placed within a JS file: var Tawk_API = Tawk_API || {}, Tawk_LoadStart = new Date(); (function() { var s1 = document.createElement("script&qu ...

Create a stylish frame for designated rows within a table

Col1 Col2 Col3 Col4 Col5 Col6 Row11 Row12 Row13 Row14 Row15 Row16 Row21 Row22 Row23 Row24 Row25 Row26 Row31 Row32 Row33 Row34 Row35 Row36 Looking for a way to add a border around rows with matching values in the first column, or around a specif ...

Clicking on the child element triggers a blur event

I have a situation where a parent element contains an input: <div @blur="onLeaveSelect($event)"> <div v-if="searchActivated" > <input type="text" placeholder="Search..." @mousedown.stop> ...