Refresh HTML dashboard panels using Vue.js

Currently, I am in the process of developing a Vue dashboard that communicates with the Woocommerce REST API. Within this dashboard, I have implemented several cards that display information such as the total orders for the day and order count. Below is an example of the HTML code for these cards:

<div class="dashbord dashbord-red">
    <div class="icon-section">
        <small>Total Sales</small>
        <p> v-for="totalsales, index in totalSales">
            Total - Total is: {{ totalsales.total_sales }}</p>
    </div>
</div>

Included above is the Vue js code snippet as well.

// creating Vue instnce
var app = new Vue({
  el: '#app',
  data: {
    orders: []
  },
  data: {
    totalsSales: []
  },
  mounted: function () {
    // Call the API the first time
    this.refreshData()
    // Then call the API every minute
    this.setIntervalId = setInterval(this.refreshData, 60000)
    // Updating cards  
    this.getTotalSalesToday()
  },

  methods: {
    getTotalSalesToday() {
      axios.get('https://staging.mysite.de/wp-json/wc/v3/reports/sales?date_min=2020-09-18&consumer_key=123&consumer_secret=123')
        .catch(error => {
          console.log(error);

        });
    }
  })

However, my concern lies in the fact that I am only able to retrieve the text within the p tag, rather than the actual value. I am struggling to identify where things are going wrong in my implementation. Your insights would be greatly appreciated. Thank you!

Answer №1

Upon inspection, I have identified several potential issues that may be contributing to the problem:

  1. There appears to be a typo within the <p> tag, as noted by Sphinx on Stack Overflow.
  2. Inconsistencies between the use of totalsSales in the data section and totalSales in the v-for loop could be causing confusion.
  3. The declaration of data seems to be repeated more than once, which might lead to conflicts.
  4. It is important to ensure that when defining components, the data should be declared as a function that returns the initial data object, as per the Vue.js documentation.
  5. The code snippet provided does not clearly show how totalSales is meant to be populated. Is the function refreshData responsible for this task? Without an interceptor setup or a proper handler like a .then block after getTotalSalesToday, it is unlikely that totalSales would get updated correctly from the server response.

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

Is there a way to access data from a previous useState hook in a subsequent useState hook?

For my current project, I am working on developing a small marketplace website that integrates with stripe Checkout. The tutorial I was following did not cover using products from an API, which is where I encountered some difficulties. The table in the AP ...

Mastering the art of invoking a JavaScript function from a GridView Selected Index Changed event

In my current setup where I have a User Control within an Aspx Page and using Master Page, there's a GridView in the User Control. My goal is to trigger a javascript function when the "Select" linkbutton on the Gridview is clicked. Initially, I succe ...

Contrasting the uses of element(...) versus element(...).getWebElement() in Protractor

What is the advantage of using element(...).getWebElement() instead of element(...) when they both perform similarly? Why are there two different APIs for the same purpose? ...

updateOne is limited to updating a single field at a time and does not have the capability to generate new fields within

I have encountered an issue with my NodeJs and MongoDB atlas setup while trying to save/update user profiles. The updateOne method seems to only update a single field at a time instead of the entire record. Here is the relevant code snippet: app.post(" ...

Using threejs to pass multiple secondary geometries into vertex shaders

Suppose I have a geometry that I am using to create points or an InstancedMesh by utilizing the vertices. However, if I want to change this underlying geometry to something else - such as from a cone to a sphere - that has the same number of vertices, how ...

Initiate a function following a 3-second click on an image

I'm facing a peculiar challenge with my website - I have an invisible button that needs to be pressed for 3 seconds in order to trigger a specific action. Here is what I've attempted so far: $("#basicChn").on({ mousedown: function() { $ ...

What is the best way to toggle the active class on a ul list?

After clicking, the active class remains on the original "li" instead of changing as it should. I've tried modifying the code but haven't been able to find a solution. Can someone please review what I might have missed? It seems like there's ...

Waiting for a function to finish within a nested function in JavaScript

I'm facing a simple issue that I'm struggling to solve. I have two functions and an object in JavaScript (Node.js) structured like this: var auxmap = new Map(); function one() { for(var i...) { //initialize the map and do something tw ...

jQuery - Is there a way to dynamically generate an element based on user input during an iteration?

My current challenge involves creating 5 unique audio players using a specific code snippet that can be called individually throughout the HTML document. You can find the original code here: https://codepen.io/katzkode/pen/ZbxYYG The issue I'm facing ...

How can I perform a cross-domain XMLHTTPREQUEST to communicate with an FTP server using the appropriate syntax?

I am currently using a webDav CORS plugin to manage files on a webDav server through POST/PUT/GET/REMOVE/ALLDOCS requests. Now, I am attempting to achieve the same functionality for FTP but am facing difficulties with the xmlhttprequest syntax (I keep rec ...

Utilize a Chrome Content Script to intercept jQuery delegated event handlers and take control

After developing a Chrome extension that intercepts form submissions in specific circumstances, I encountered an issue with a particular website utilizing jQuery's delegate function. My extension is built with raw JavaScript, excluding jQuery to prev ...

Error caused by a null injector when sharing an Angular module that contains different @angular/material modules

My uiModule is set up to import and export various @angular/material modules. I was expecting that by importing uiModule into anotherModule, anotherModule would have access to the @angular/material components. However, this doesn't seem to be working ...

React component with adjustable zoom settings

I'm searching for a way to implement a zoomable element in React. My goal is to display a larger image and additional information when clicking on any picture from a list of pictures. Upon clicking again, I'd like the image to zoom out. Can anyon ...

Error occurred while attempting to cast the query selector result to an HTMLElement within the <script lang="ts"> section of a vue component

My Vuejs project includes a component with the following mounted method: mounted() { try { let x = 'abc'; console.log(x); let body = <HTMLElement> document.querySelector("body"); } catch (e) { console.log(e); ...

Updating Material-UI DataGrid Component with Fresh State Information

Hey there, We've integrated Material-UI into our project to build a DataGrid table of users where we can delete selected entries (checkbox) using a button. Whenever the button is clicked, it triggers an update in the object's state (removing th ...

What is the best way to make a canvas element always follow the movement of the mouse cursor

Currently, I am delving into the world of HTML5 canvas and experimenting with a program that rotates a triangle to face the location of the mouse pointer. The functionality is mostly there, but it seems to skip half of the intended rotation. I am curious i ...

Receiving undefined when trying to access an array within the state in React

When I use console.log(this.state.animal_names), the output is >(2) [Array(2), Array(2)] Upon expanding, I see 0: (2) ["dogNames", Array(53)] 1: (2) ["catNames", Array(100)] However, when I attempt to access them like this: desiredAnimal = "dogNames ...

Using Jquery's closest technique to target a class located outside of the parent div

I am having trouble accessing a class outside of its parent div $(document).on('click', '.delete_photo', function(event){ var del_id = $(this).attr('id'); $.ajax({ type:'POST', cache: false, url:&apo ...

retrieve the URL of a freshly opened page following a click

I am currently in the process of developing a test that involves clicking on a button to open a new tab and redirecting to a different website. My objective is to retrieve the value of this website for parsing purposes, specifically after the rfp code in t ...

Encountering issues with upgrading Vue.js 2.5.2 with TypeScript

I am currently in the process of updating vue js to version 2.5.2 along with typescript 2.5.3. Below is my index.ts file: import Vue from 'vue' var app = new Vue({ el: '#app', data: { message: 'Hello Vue!' ...