Nuxt fails to accurately display real data

I am perplexed by the issue that causes my code to jump straight to

'This is empty'

Even though the value of viewDetails[0] is not empty

fullName() {
      return this.updateData?.viewDetails?.mock_name
        ? this.updateData.viewDetails[0]?.mock_name
        : 'This is empty'
    },

I anticipate the output to display the content within viewDetails[0], which should contain the name of a person, rather than defaulting to This is empty when viewDetails[0] actually contains data.

Answer №1

It seems that this.updateData.viewDetails is actually an array, correct?

Therefore,

this.updateData?.viewDetails?.mock_name
does not exist at all. You are attempting to access mock_name on an array, rather than an element within the array. In other words, you forgot to include [0].

You should simply do this:

fullName() {
   return this.updateData?.viewDetails?.[0].mock_name || 'This is empty'
},

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

Unable to send or receive data through socket.io

I am currently working on a project that involves draggable divs and the use of sockets.io to synchronize their positions across different clients. In my client-side code (index.html), I have the following setup: // Locating the draggable elements var el ...

What could be causing the VueJS function not to be triggered by the dropdown selection?

I created a simple component called LocaleSwitcher.vue using the Element UI library: <template> <el-dropdown trigger="click"> <div> <i class="el-icon-map-location"></i> </div> < ...

In HTML5, I am trying to figure out the best way to connect my webpage sections to the corresponding navigation links with the help of IDs (such as linking navhome to

I am in the process of redesigning a website to optimize it for mobile devices. Although I have completely restructured the site, I am encountering an issue where the main pages are not displaying properly. The header, navigation menu, sidebars, and a plac ...

Using a Node.js module to shrink HTML files

Is there a way to minify HTML before rendering it? I'm aware of console minifiers like: html-minifier However, I am looking for a solution that can be implemented in the code itself. Something along the lines of: var minifier = require('some- ...

Is there a way to retrieve the specific URL entered into the browser directly from server-side files?

Is there a way to retrieve the URL entered in the browser on the server side using JavaScript within server files? My project is built with React, and I am unable to utilize window.location.href since the window object is limited to the client-side. ...

Troubleshooting a scope problem in Angular 1.2 directive

When you create a directive with an isolated scope, no template within the directive, but there is some dom elements inside the directive, those dom elements cannot bind to the scope of the directive. <div ng-controller="testCtrl"> {{hehe}} ...

Is it possible to retrieve event information from an i element when it is clicked on?

I am currently iterating through a set of icons that each have a specific value (the icon type and value are passed as props). However, I am facing an issue where I want to trigger a click event that will update the state with certain keys, values, or IDs ...

JavaScript event/Rails app encounters surprising outcome

I have encountered a strange bug in my JavaScript code. When I translate the page to another language by clicking on "English | Русский" using simple I18n translation, my menu buttons stop working until I reload the page. I suspect that the issue ...

What is the best way to present progress bar numbers in Bootstrap beneath the bar?

I have successfully implemented a progress bar using Bootstrap. Now, I am looking to display numerical values below the progress bar, similar to this: https://i.sstatic.net/3QG8d.png Is there a way to achieve this without utilizing JavaScript graphing l ...

The color of the vertices is transitioning to a pure white hue

When working with THREE.js points, I often find the need for them to have different colors on a per-point basis. In some cases, I also adjust the alpha value, which leads me to write my own shader programs. Here is the JavaScript code I am using: let mat ...

Refreshing ng-repeat dynamically with $http without reloading the page

Just a quick heads-up, I'm new to AngularJS In my AngularJS application, I am using the $http service to fetch data. Each row has an update button that needs to trigger a server-side method (the API is already returning data) to sync with a third-par ...

Conditional radio button disabling in Material-ui

Currently, I am developing a React application using material-ui. My goal is to disable all radio buttons within a RadioGroup when a specific event occurs, and then re-enable them once the event is no longer active. For example, when a button is clicked, ...

What is the best method for storing numerical data for a Next.js/React website? Should you use a CSV file, make a backend API call, or download

I'm working on a nextjs website and I want to integrate a chart. Where would be the best place to store the data for this chart? Here are some options I've considered: Save a csv file in the public folder and retrieve it from there Store a csv f ...

After ReactDOM is used, the JavaScript code is no longer functioning properly

While working on my latest project, I utilized react.js and encountered an issue where javascript seemed to stop working when using ReactDOM to render a class extended from React.Component. I noticed that the alert() method would not work if it was placed ...

What is the best way to securely store a client secret within a JavaScript application?

What is the best way to safeguard a client secret in a JavaScript application in order to ensure it is inaccessible to unauthorized users? Specifically, I am working with an AngularJS SPA. In my case, the client secret is a guid created during login and t ...

A React child error has occurred in Next.js due to invalid objects being used

Within my project, I have integrated the latest version of next.js and encountered an issue where objects are not valid as a React.js child. https://i.stack.imgur.com/MCO7z.png The problem arises after importing the Head component from Next.js and implem ...

Bring in camera from gltf

Can someone provide guidance on utilizing a camera from gltf within three-js? I am currently implementing the gltf loader as demonstrated in this example. ...

Encountering Undefined Value when Parsing JSON with JavaScript

Currently, I am immersed in a project that involves using Javascript and JSON Objects to dynamically populate data in a popup modal. The process unfolds as follows: when a user clicks on the title of a feedback issue, the relevant data is fetched from the ...

JavaScript Naval Combat Game

I created a basic battleship game using javascript, but unfortunately it's not working properly. I stored the ship locations in an array and attempted to remove guessed locations by using the splice method. However, it keeps displaying "MISS!" when nu ...

jQuery code isn't functioning properly when I include the script using the complete URL

When I include the local jQuery like this, everything works fine: <script type="text/javascript" src="jquery-1.11.2.min.js"></script> However, when I try to link it from my server, things don't work as expected. I double-checked by openi ...