The computed function functions smoothly in one component but encounters issues in a different one

After adding multiple components to a page, I noticed that updates made to a parent object are reflected in one component but not the other.

The main page, PatientEditor.vue, includes the following components:

<notes-editor v-model="pt" />
<chart-completion v-model="pt" arrange="horiz" />

and contains this script:

module.exports = {
  props: ["pt"]
};

Therefore, the pt object resides within the parent and is passed to various components as a v-model.

One of the components, ChartCompletion.vue, functions correctly with the following code snippet:

module.exports = {
  props: ["value", "arrange"],

  computed: {
    completed_notes: function() {
      return this.value.notes.filter(function(note) {
        return note.signed_at;
      }).length;
    },

However, the problematic child seems to be the NotesEditor.vue template which includes the following structure:

module.exports = {
  props: ["value"],

  computed: {
    completed_notes: function() {
      return this.value.notes.filter(function(note) {
        return note.signed_at;
      }).length;
    }
  },

It might not be crucial, but the notes object is populated from an ajax call in another component like so:

this.value.notes.splice(0, this.value.notes.length, ...response.body.notes);
this.$emit("input", this.value);

Consequently, when changes are made to this.value.notes, they reflect properly in the ChartCompletion component but not in the NotesEditor component. Upon inspecting the Vue debugger in Chrome, it's evident that the notes object undergoes modifications. However, for some reason, the computed property fails to recompute, despite having the exact definition in the ChartCompletion component. Furthermore, the v-for present in NotesEditor also remains unchanged.

What would be the best approach for debugging this issue?

EDIT 1 - addition of the NotesEditor component

<template>
  <span>
    <table class="table">
      <thead>
        <tr>
          <th>Date</th>
          <th>Status</th>
          <th>Audio</th>
          <th>Text</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="n in value.notes" :key="n.id">
          <th>{{n.created_at}}</th>
          <td>{{n.note_status_id}}</td>
          <td>
            <span v-if="n.audio_length > 0">
              <audio controls="controls" preload="none">
                <source :src="audioURL(n.id)" type="audio/webm"> Your browser does not support the audio element.
              </audio>
              ({{n.audio_length}}s)
            </span>
            <span v-else>
              None
            </span>
          </td>
          <td>
            <span v-if="n.note_text">
              <button data-toggle="tooltip" :title="n.note_text" class="btn btn-outline-primary btn-sm" @click.prevent="openChartEditor(n.id)">
                <span class="glyphicon glyphicon-edit"></span> Edit Note ({{ n.note_text.length }} chars)
              </button>
            </span>
            <span v-else>
              <button class="btn btn-primary btn-sm" @click.prevent="openChartEditor(n.id)">
                <span class="glyphicon glyphicon-pencil"></span> Create Note
              </button>
            </span>
          </td>
        </tr>
        <tr>
          <td colspan="3">
            <record v-model="value" />
          </td>
          <td>
            <button class="btn btn-primary" @click.prevent="openChartEditor(0)">
              <span class="glyphicon glyphicon-pencil"></span> Create Note
            </button>
          </td>
        </tr>
      </tbody>
    </table>
  </span>
</template>


<script>
module.exports = {
  props: ["value"],

  data: function() {
    return {
      sendFaxWorking: false
    };
  },

  computed: {
    completed_notes: function() {
      return this.value.notes.filter(function(note) {
        return note.signed_at;
      }).length;
    }
  },

  methods: {
    audioURL: function(id) {
      return "/notes/getAudio/" + id;
    },

    openChartEditor: function(id) {
      this.$root.$emit("showEditor", id);
    }
  }
};

Answer №1

Although I have doubts about the effectiveness of this solution, it does manage to get the job done. A watcher function has been implemented that triggers $forceUpdate()

  mounted: function() {
    this.$watch("value.notes", this.$forceUpdate);
  },

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

Emscripten WebAssembly: Issue with Exporting Class "Import #13 module="GOT.func" error: the module does not exist as an object or function"

Exploring the potential of WebAssembly in a project as an importable function module, I decided to dive into using C++ with Emscripten. Implementing functions was smooth sailing, but running into obstacles when it comes to classes. My goal is to expose and ...

Adjust multiple components at once

I'm working on creating a "textarea" with a toolbar that displays rich text content based on the HTML content stored in the background textarea. Here is an example of the HTML structure: <div class="primary-content"> <div class=" ...

React 17 Form not registering the final digit during onChange event

I am currently experiencing an issue with a form that includes an input field of type "number." When I enter a value, the last number seems to be skipped. For example: If I input 99 into the box, only 9 is saved. Similarly, when typing in 2523, only 252 ...

Issue encountered when attempting to display JSON index on individual result page

This is a JSON response. { "listing": { "id": "1", "name": "Institute Name", "contact": "9876543210", "website": "http://www.domain.in", "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" da ...

Ways to monitor the status of a server request using jQuery (ajax)?

I am currently working on a PHP application that involves users submitting forms to the server via ajax (jQuery). The server needs to insert a large number of records into a MySQL database, which may take some time due to various calculations. My question ...

I am having trouble retrieving the array value from the response sent by my server

After receiving a dictionary from my server, when I try to access the values using the following code: {"filters":{ "Facture": [ "Магма (Тычок)", "Тонкий кирпич", "Гладк ...

Is there a way to execute a node script via command line sans the need for installation and external packages?

Is there a way to execute a node script from the command line during development without actually installing anything, but still having access to installed packages using npm install <...>? When I try node ./bin/my_script.js, the script does not reco ...

Create a Buffer that includes all the characters of the alphabet when converted to

My current project involves using Node.js to generate secure, random tokens. Here is a snippet of the code I'm using: crypto.randomBytes(32).toString("hex"); // dd89d6ab1a7196e8797c2da0da0208a5d171465a9d8e918d3b138f08af3e1852 Although this method wo ...

Is it advisable to approve automatic pull requests initiated by dependabot for updating the yarn.lock file?

I've recently received some pull requests from "dependabot" in a JavaScript library I am working on, like the one found here. While I appreciate the effort to update dependencies to newer versions, it seems strange that each PR only updates the versi ...

How can I style the inner div by adding a class to the first div?

In my project, I have a list of elements that are generated dynamically, all styled the same way but with different content. The first element has a specific styling, and if it doesn't render, I want the second element to inherit that styling. < ...

Looping through values in VueJS from 100 to 0

I am currently working on creating a power meter that will smoothly transition from 100 to 0 and back again to 100. The idea is for the user to press a button, causing the meter to stop at a random value. I just need some assistance in getting the loop fu ...

What causes the exception in JavaScript to be an empty object?

try { let temporary = null; temporary.split(','); } catch (error) { Logger().info('caught error: ', error, error.constructor); } output: caught error: {} undefined I attempted to use JSON.stringify and encountered the sa ...

The error message "window is not defined" occurs when the external file 'signalr.min.js' is included

Updates OpenTest --version 1.2.2 ChromeDriver 85.0.4183.87 Whenever I attempt to add the necessary external javascript files, it results in the following errors: Caused by: java.lang.RuntimeException: Failed to evaluate JavaScript code at line number 1. ...

checking the validity of serialized information in Ajax

I am facing a specific issue where I need to validate data before it is saved through an ajax call. When the user switches to a different URL, the save_ass_rub function is triggered. Within my application, there is a custom Window that allows users to inp ...

Press a button to delete an item from the array

I am currently utilizing angularJS for the development of a Single Page Application (SPA). My challenge lies in deleting an object from an array within my controller, particularly while using ng-repeat. Below is the relevant HTML snippet: <div class="c ...

What are some strategies for implementing a basic search function using arrays in JavaScript?

Is my approach to creating a search function using arrays instead of a database correct? <script type="text/javascript> $(document).ready(function() { $(document).on('submit', '#sample', function() { var inputs = docu ...

Upon refreshing, the user of the React JS application is redirected to a different page

My React JS app utilizes react-router-dom v6 to manage the routes. Everything was working fine until I integrated Firebase Firestore. Now, when I reload the seeker page, it redirects me to the home page instead of staying on the seeker page. This issue is ...

Switch the values between two TextFields using Reactjs with material-ui

I am facing a challenge with my React components. I have a functional component that handles user input and it is nested within a class component that manages the state containing the input data. The issue arises when I try to implement a function in the c ...

Extracting IDs, classes, and elements from a DOM node and converting it into a string format

Can someone please guide me on how to extract the DOM tree string from an element? Let's consider this HTML structure: <div> <ul id="unordered"> <li class="list item">Some Content</li> </u ...

React's Dynamic Table fails to rerender when updated values are placed in the same row and under the same header

Here is the table generated by my functional component: <table class="table"> {/* Consonant Table */} <tr> <th colSpan="2">---</th> {headersPOA. ...