Adjust counter to allocate points based on team in Vue.js

Currently, I am tackling a Vue.js 3 school assignment that involves a dynamic number of teams competing in a football championship. The team data is stored in a JSON format and accessed via an API. The task at hand requires selecting two teams - one representing the home team and the other the visitor team - to compete against each other. The goal is to award a point to one of these teams and update the scoreboard accordingly. The points are managed using Vuex within a store. However, I am facing challenges with ensuring that the points are allocated correctly to each team. I have attempted to use an if-else structure, but it is giving points to both teams simultaneously. I am struggling with passing the parameters accurately and would greatly appreciate any guidance on this issue.

Here is my current code:

store.js

import {createStore} from 'vuex'
import axios from 'axios'

const store = createStore({
  state() { 
    return {
      teams: [],
      house_points: 0,
      visitor_poins: 0,
    }
  },
  getters: {
    total_house: state => state.house_points,
    total_visitor: state => state.visitor_poins
  },
  mutations: {
    load_team(state, teams){
      state.teams = teams
    },
    count_house_points (state) {
      state.house_points++
    },
    count_visitor_points (state) {
      state.visitor_poins++
    },
  },
  actions: {
    load({commit}) {
      axios.get('http://localhost:3000/teams').then(({data}) => {
        commit('load_team', data)
      })
    },
    count_house_points ({commit}) {
      commit('count_house_points')
      axios.get('http://localhost:3000/points').then(({data}) => {
        commit('count_house_points', data)
      })
    },
    count_visitor_points ({commit}) {
      commit('count_visitor_points')
      axios.get('http://localhost:3000/points').then(({data}) => {
        commit('count_visitor_points', data)
      })
    },
    
  }
})

The application:

Answer №1

Issue resolved, I discovered that one of my inputs was not receiving the accurate value when the if-else structure was called. I had to move the call to a different location.

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

There was an error during module build process: ReferenceError occurred due to an unrecognized plugin "import" specified in "base" at position 0

I have encountered an error while working on my ReactJS project using create-react-app. The error arose after I added and removed a package called "react-rte". Now, every time I try to start my project, I get the following error: Error in ./src/index.js Mo ...

Tips for transforming a JSON string into an array of specified types using Gson!

I have a Request class that represents a request to execute a specific method on a server. It has fields for service name, method name, and an array of serializable arguments. When serializing the Request object using Gson, I specify all arguments through ...

Combining ReactJS event handling for onClick and onKeyDown into a single handler for TypeScript

To ensure accessibility compliance, I am incorporating onKeyPress handlers into my application. However, I am facing a challenge with interactive <div /> elements. Here are the event handlers I want to trigger on click: const handleViewInfoClick = ( ...

Angular UI Bootstrap collapse directive fails to trigger expandDone() function

I am currently utilizing UI Bootstrap for Angular in one of my projects, and I have developed a directive that encapsulates the collapse functionality from UI Bootstrap. Here is how it looks: app.directive( 'arSection', ['$timeout', fu ...

Utilizing d3.json: changing the URL with dynamic data

Just getting started with d3 and building a sankey diagram. I came across a sample that uses an external .json file with d3.v3, even though it is an outdated version. Since my tree also relies on this version, I'd like to stick to just one d3 version. ...

What is the best approach for maintaining data when transitioning between tabs in Vue?

Currently delving into the world of Vue, I've created a tab component with 2 tabs containing dropdowns and text fields. The issue arises when switching between tabs as the selected items in dropdowns or text values are lost. I attempted to use v-model ...

Transferring JSON data back and forth between C# and PHP files

I am trying to send a JSON request from C# to a PHP file in order to save data into a text file. However, the PHP file is unable to read the data. Below is my code: User user = new User { id = 1, name = "Bob", address = "password", phone = "0111111111", a ...

Having difficulty retrieving information from Redux store

In my project, I utilize the Redux store to manage data. Through Redux-DevTools, I can observe that initially the data is null but upon refreshing the page, the data successfully populates the store. However, when attempting to retrieve this data within on ...

What's the reason behind this being Undefined? Is there a way to resolve this issue?

After loading the `empresas` in the function, when attempting to retrieve it using `console.log(this.empresas[0]);` it gives an error saying it is undefined. empresas: any; constructor(...) { this.getEmpresas(); console.log(this.empresas[0]); } getEmp ...

Mastering the art of debugging VueJS using Chrome's powerful breakpoint tools

Currently I am a developer who primarily uses VIM, and I have been exploring ways to leverage chrome breakpoints for debugging in my Vue.js app. In addition, I am utilizing nuxt alongside Vue for app development. I am curious if anyone has successfully ma ...

Creating redux reducers that rely on the state of other reducers

Working on a dynamic React/Redux application where users can add and interact with "widgets" in a 2D space, allowing for multiple selections at once. The current state tree outline is as follows... { widgets: { widget_1: { x: 100, y: 200 }, widg ...

Using Angular service within InnerHTML functions

Within my Angular 10 application, I am utilizing innerHtml to display some content that includes anchor links. My goal is to trigger a function every time a link is clicked, which will then invoke an Angular service. In the code snippet below, I am attac ...

"Troubleshooting: Extracting Only the Initial Row from JSON Data in Pandas Data

I'm currently working on a web scraping project and have managed to produce the desired JSON data format by using the #print command. However, when attempting to run the same code with Pandas Dataframe, I am only receiving the first row of data instea ...

Trouble with Angular toggle switch in replicated form groups

Currently, I have a form group that contains multiple form controls, including a toggle switch. This switch is responsible for toggling a boolean value in the model between true and false. Depending on this value, an *ngIf statement determines whether cert ...

What is the most effective way to extract all Arrays from a JSONObject?

I need assistance with extracting data from a JsonObject structured like this: { "status": "ok", "data_EN": [ { "id": 1, "url" :"http://example.com" } ], "data_FR": [...], "data_ES": [...] } I have created a method to retri ...

Encountering a high volume of requests error while attempting to retrieve data from the API using the NodeJS backend, yet functioning properly on the React

While attempting to retrieve data from https://api.solscan.io/chaininfo using a NodeJS backend application, I encountered an error stating 429: Too many requests. Interestingly, the same API functions without any issues when utilized in a React frontend a ...

How can I configure my data source in Kendo UI to reference a specific item within the object returned by a JSON callback?

Currently, I am implementing KendoUI autocomplete to filter data as users type into a textbox. However, I am facing an issue with the autocomplete functionality. When I type into the field, the search begins, the service is called, and the JSON result/Cal ...

PhpStorm now offers the convenient feature of automatically completing JavaScript modules directly from the Resource Root

I am currently utilizing PhpStorm as my chosen IDE and I am looking to import my JS modules from the Resource Root with the @ prefix. I have designated the src directory as the 'Resource Root' and I have also enabled the "Use path relative to the ...

Combining Multiple Properties in a Single-File Component with Vue.js 2

Currently, my project involves Laravel 5.5 & Vue.js 2.x. After extensive research and seeking answers, I began working with components. However, I am encountering a warning message upon page rendering: [Vue warn]: Property or method "trimestral" is not def ...

Troubleshooting Issues with Google Analytics Internal Link trackEvent Functionality

Using ga.js, I have encountered an issue with tracking internal links on my website. Despite successfully tracking external links and viewing real-time reports for events, the internal links are not being recorded accurately. While testing pages, the tot ...