How to retrieve information from an array using VueJS

I am currently encountering an issue where I need to extract a parameter from the URL in order to dynamically display data. However, I am struggling to find the solution.

Which parameter should I use in state.event.aftermovies[] to access the ID of my object?

If anyone has a solution, I would greatly appreciate it.

<template>
  <div>
    <div class="container text-center">
      <div>
        <h1>{{ aftermovie.id }}</h1>
        <h1>{{ aftermovie.name }}</h1>
        <h1>{{ aftermovie.slug }}</h1>
        <h1>{{ aftermovie.video }}</h1>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex'
export default {
  async fetch({ store, error, params }) {
    try {
      await store.dispatch('fetchEvent', params.id)
    } catch (e) {
      error({
        statusCode: 503,
        message: 'Unable to fetch event #' + params.id,
      })
    }
  },

  //Facing an issue here
  computed: mapState({
    aftermovie: (state) => state.event.aftermovies[??????????????????]
  }),
  head() {
    return {
      title: this.aftermovie.name
    }
  }
}
</script>

Additionally, I would like to retrieve the ID of my object.

event:Object
address:"Belgium"
aftermovies:Array[1]
0:Object
event_id:1
festival_id:""
id:4
name:"reverze 2020"
slug:"reverze-2020"

What is the proper approach to achieve this??

Answer №1

If you have an array called aftermovies with objects inside, such as:

aftermovies: [{
  event_id:1,
  festival_id:"",
  id:4,
  name:"reverze 2020",
  slug:"reverze-2020"
}]

You can access the id of the first object like this: aftermovies[0].id

Check out this jsfiddle example

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

Utilizing Vue.js: Dynamically Rendering Components Based on Routes

I needed to hide some components for specific Routes, and I was able to achieve this by using a watcher for route changes that I found in this StackOverflow question - Vuejs: Event on route change. My goal was to not display the header and sidebar on the c ...

Using vue-select: In VueJs, how to pass an option slot from a grandparent component

Utilizing a custom dropdown component called 'vue-select', there is an option to customize the options view using slots as detailed in this documentation -> https://vue-select.org/guide/slots.html I am aiming to achieve a similar customizatio ...

Angular: The Ultimate Guide to Reloading a Specific Section of HTML (Form/Div/Table)

On my create operation page, I have a form with two fields. When I reload the page using window.reload in code, I can see updates in the form. However, I want to trigger a refresh on the form by clicking a button. I need help writing a function that can r ...

What are the potential disadvantages of relocating the login logic from the 'signIn()' function in NextAuth.js?

My experience with NextAuth.js for the first time has led me to realize that signing in using the Credentials provider can be a bit tricky when it comes to error handling. It seems like the default implementation should resemble something along these lines ...

Extract the body.req object within a loop in a Node.js application

I'm looking to efficiently parse and save the body of a POST request using Mongoose in Node.js. Is there a way to use a for loop to accomplish this task, rather than manually saving every property? My ideal solution would involve something like: for ...

Issue with Vue JS: e.preventDefault not functioning correctly when using Axios

I am facing an issue in my Laravel project where I have implemented a method in the Vue instance to validate resource availability upon form submission. The validation is done through an AJAX call using axios, and if any resources are unavailable, I receiv ...

Performing a MongoDB query in a controller using the MEAN stack with Node.js

My goal with this controller is to retrieve all the results of a collection. Despite having one item in the prop collection, I am encountering an undefined error. Error: Cannot call method 'find' of undefined This snippet shows my server.js fil ...

Calculating the total sum in Vuejs when an event is triggered

I am faced with a situation where the price of a product is added to an existing total when a user increases the quantity. However, the problem lies in the fact that even if the user decreases the quantity, the price continues to increase. Solution html ...

How can ternary conditional operators be transformed into if statements?

When dealing with minified code like this, f&&!f.error?k.button.b==k.button.c.G?k.button.Q(b,e,f,c,d):k.button.b==k.button.c.o&&k.button.P(b,e,f,c,d):(console.error(f),f=f.error.message||chrome.i18n.getMessage("error_tooltip"),k.button.v(b ...

A grid displaying relationships between elements, with both the vertical and horizontal axes labeled using

To establish an Adjacency matrix with rows and columns represented by Strings and containing either 0 or 1 to indicate a connection between the source and destination nodes. For instance, if a connection exists from a to b and b to c, the matrix would loo ...

How do I overwrite this calculation using JQuery?

I have a website: link There are two pages on my site that have the same div elements... I want one page to perform a certain calculation on the divs, and another page to perform a different calculation... New JavaScript Code: jQuery(document).ready(fu ...

Unable to locate the slim JWT token in the axios request

Currently, I am in the process of creating a Vue js/Vuetify website that utilizes a PHP Slim Framework API with tuuopla slim-jwt-auth serving as the middleware for JWT token authentication. While the unprotected routes are functioning correctly, I have enc ...

Sending a user to an external website through an XML response

In my current project, I am utilizing jQuery to fetch a PHP file. The PHP file executes a cURL request to an external website in order to obtain information for a payment request. The external site responds with XML data structured as follows: <Request ...

What is the reason for the find() method not displaying the most recent data from a MongoDB database in an Express.js application?

Upon calling the app.post('/form-submit', funtion(req, res)) method, my expectation is for it to first save the data using save(). This works fine, but then when I call the find() method, it shows all the data from the mongoDB database except for ...

Proceed with executing the function only if the current date is before the specified date

I've created a countdown timer that can count both up and down from a given date. However, I want the countdown to only run in reverse and stop once it reaches the current date or any future dates. Currently, the alert message shows when the date is r ...

Is there a way to send an AJAX request to an MVC action from a JavaScript file?

In a file named job.js, there is code that works perfectly when run on localhost but results in a 404 error when run on an intranet server with an application name. Job.updateJob = function () { $.post('/Builder/ListJobItems', function (dat ...

Retrieve the name of the selected item in the antd dropdown component

I am facing an issue where I cannot retrieve the name of the select component in Ant Design to use the handleInputChange function on its onChange event. As a workaround, I decided to update the state directly in the onChange event by adding it to an obje ...

Is Riot.js the best choice for server-side rendering and routing?

Currently, I am using Node along with Riot.js and the Grapnel routing library. I have successfully set up routing on the client side, but I am facing difficulty in making it work on the server side. The functioning of my client router is straightforward. ...

Exploring methods of simulating properties using jest.fn()

Here is the code snippet I'm currently working with: this.$vs.loading() .... this.$vs.loading.close() To successfully pass a mock to shallowMount, I have set it up as follows: const vs = { loading: jest.fn() } mocks: { $vs: vs } However, the ...

jQuery fails to operate on products loaded through AJAX requests

Upon opening the page, jQuery functions correctly. However, when a product is loaded or changed via AJAX, jQuery stops working. I am currently using jquery-1.7.1.min.js $(document).ready(function () { $screensize = $(window).width(); if ($screensi ...