Having trouble accessing a value in Vue.js from the data object

I'm facing an issue with displaying data pulled from an API in my vue console. Despite it showing up there, I can't seem to get it to show in my markup. Specifically, the advertiser_id field always appears blank even though other data like clicks, earnings, and orders display fine using v-html.

Could this be due to the data being somehow read-only or protected? I find it strange that it shows up in the vue console if that were the case.

The structure of the API response is as follows:

{
  "1": {
    "advertiser_id": "3184",
    "clicks": "27,577",
    "orders": "10,722",
    "earnings_per_click": "257.11",
  },
}

Answer №1

If my interpretation is correct, it could be implemented as shown in the code snippet below (utilizing v-for for object iteration)

const app = Vue.createApp({
  data() {
    return {
      item: {
        "1": {
          "advertiser_id": "3184",
          "clicks": "27,577",
          "orders": "10,722",
          "earnings_per_click": "257.11",
        },
      }
    };
  },
})
app.mount('#demo')
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<div id="demo">
  <div v-for="(val, key, i) in item['1']" :key="i">
    {{ key }} - {{ val }}
  </div>
</div>

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

My React application did not display properly after deploying it on GitHub Pages

I attempted to deploy my React app on GitHub Pages, but unfortunately it did not work as expected. When I tried to access the link, all I got was a blank page. Can anyone help me with a solution? Your assistance is much appreciated! Here's a snippet ...

JavaScript consistently returns HiddenField as NULL

After creating a Context menu and associating it with a Gridview, I noticed a problem when pressing a button from the context menu. I intended to retrieve a value from a HiddenField, but it always returns null. My assumption is that the DOM might not be fu ...

Exploring ways to retrieve a parent div from a child window

Within my parent window, I have a div where I want to display newly entered records that are added into the database. The following code snippet represents the div within the parent window: <div id="divTable"></div> A button resides in the c ...

Preventing multiple clicks by toggling the HTML tag on and off

Here is the jQuery structure that I am currently working with: $(document).on('click', '.view-details', function () { $(this).prop("disabled", true); // API call1 // API call2 // API call3 $(this).prop("disabled" ...

Is there a solution to successfully retrieving the value of res from the readCsv() method instead of it returning undefined?

In this scenario, I have a file uploader that accepts .json and .csv files. When the upload button is clicked, the HomeComponent calls the service dataparser which has two functions: readJson and readCsv. One function returns an observable while the other ...

onload function prevents further URL redirection

After submitting the form "View this product," a function is triggered to retrieve the product id from the form data. Although I can successfully obtain the form_data, the page does not redirect as expected. I suspect that my function may not have been pr ...

Mapping an array based on specific conditions

When using my photo gallery app, I faced a challenge in mapping an array of images based on the user-selected album name. The current setup works perfectly for the 'Cambodia' album where all images are correctly logged in the console after mappin ...

Tips for managing a fixed-positioned element during scrolling and zooming events

I have a situation where I need a fixed-position element to stay at the top-right corner of the viewport. Here is the HTML code: <div class = "header"> <p>This heading has an absolute position</p> </div> And here is the CSS: .he ...

Explore jQuery to locate a specific anchor element that has a matching URL and then apply a new class

I am looking to highlight both the parent and child items in a navigation menu by returning URLs as an array based on the current page. The structure of my basic navigation is as follows: <div id="cssmenu"> <div id="menu-button"></div&g ...

Storing a reference within another reference can diminish its reactivity

I'm encountering an issue with nested refs. Whenever I try to access the inner refs, I only receive back the values instead of the reactive variables. My situation involves a Pinia store, but I've simplified it down to the essential components. ...

The userscript is designed to function exclusively on pages originating from the backend, rather than on the frontend in a single-page application

I have a userscript that I use with Greasemonkey/Tampermonkey. It's set to run on facebook.com, where some pages are served from the backend during bootstrapping and others are loaded on the fly in the front-end using HRO, similar to how a Single Pag ...

"Exploring the world of AngularJS through Onsen's API

Having trouble transitioning between pages in your mobile app using Onsen UI? Check out the code snippet below from my app.js file, which aims to share data between pages during the transition. // Wordpress Posts Controller var app = angular.module(' ...

What is the best way to determine the total number of pages for posts

Hello there! I'm currently working on implementing an infinite scroll feature for a custom post type, but I'm stuck on how to obtain the max_num_pages and pass it to JavaScript. Below is my current implementation of the infinite scroll: containe ...

Can dynamic variables be incorporated within a const?

Could dynamic variables be used in the code below? const [viewport, setViewport] = useState ({ latitude:-8.683895, longitude:115.152307, width:800, height:440, zoom:16 }); I want the latitude and longitude to be flexible, like this: co ...

Displaying column data in a popup modal using DataTables

I am facing an issue with displaying a long string from a column in my table in a popup modal. Upon clicking the button to launch the modal, instead of opening the modal, the page refreshes and nothing is logged to the console. Below is the HTML code for ...

What is the best way to delete a single asterisk from the content of an HTML <td> element?

Looking for a way to remove or replace an asterisk from the inner content of a <td> element. I have a block which includes some text and an input field. For this example, let's say <td> == this $(this)[0].innerHTML "*&nbsp;<input ...

Difficulty in accurately retrieving the value in a PHP echo statement using jQuery

$id = "123"; When on the page book.php, $id is passed to an external jquery-book.php file. <script type="text/javascript"> var id = '<?php echo $id; ?>'; </script> <script type="text/javascript" src="jquery-book.php"& ...

Constructing a regular expression

I've been exploring JavaScript regular expressions and encountering some challenges while trying to build a larger one. Therefore, I have decided to seek help for the entire problem rather than just individual questions. What I am looking for is a re ...

jQuery Toggle and Change Image Src Attribute Issue

After researching and modifying a show/hide jQuery code I discovered, everything is functioning correctly except for the HTML img attribute not being replaced when clicked on. The jQuery code I am using: <script> $(document).ready(function() { ...

A guide on converting nested arrays within a JSON file into a table format in Google Sheets (possibly leveraging Javascript?)

After successfully connecting via OAuth2 to retrieve a JSON performance report for shares, I am curious about how to convert this object into a matrix format within Google Sheets. { "id": "ID-23035", "total_gain": 11795.72, "holdings": [ ...