Vue.js 2 view failing to update after modifying data in Vuex state

Greetings, I am currently working on developing a table to monitor the validation status of multiple items.

Below is the VueX store configuration:

  mutations: {
...,
    set_scaninfos: function (state, scaninfos) {
      Vue.set(state, 'scaninfos', scaninfos)
    }
  },
  actions: {
...,
    setScanInfo (store, scinfo) {
      store.commit('set_scaninfos', scinfo)
    }
  },

Firstly, within the component, I initialize the scaninfos in the Vuex store as follows:

 initScanInfos () {
   var scanIds = this.$store.state.scanids
   console.log(this.$store.state.scanids.length)
   for (var i = 0; i < scanIds.length; i++) {
     this.scaninfos[scanIds[i]] = Object.assign({}, this.ruleForm)
   }
   this.$store.dispatch(‘setScanInfo’, this.scaninfos)
 }

Upon receiving updates, I update the data by pushing them using this method:

  saveForm (formName) {
    this.$refs[formName].validate((valid) => {
      if (valid) {
        console.log('form valid!')
        this.ruleForm.validated = true
        var scanId = this.$store.state.scanids[this.scanindex]
        this.scaninfos[scanId] = Object.assign({}, this.ruleForm)
        this.$store.dispatch('setScanInfo', this.scaninfos)
        this.saveSuccess()
      } else {
        console.log('error: form invalid!!')
        this.ruleForm.validated = false
        this.saveFail()
        return false
      }
    })
  },

The presentation of the data is handled as shown below:

computed: {
  scanId () {
    var pId = this.$store.state.scanids[this.scanindex]
    return pId
  },
  scinfo () {
    var scinfo = this.$store.state.scaninfos
    return scinfo
  }

The HTML representation looks like this:

    <table class="scantable">
        <tr>
            <th>scan</th>
            <th>validation</th>
        </tr>
        <tr v-for="scanid in $store.state.scanids">
            <td>{{ scanid }}</td>
            <td>
                <i v-show="!scinfo[scanid].validated" class="el-icon-close"></i>
                <i v-show="scinfo[scanid].validated" class="el-icon-check"></i>
            </td>
        </tr>
    </table>

The raw data structure is a bit complex, here's an example nested JSON dict:

{ "Ex1": { "pseudonym": "asd", "yob": "2009-12-31T23:00:00.000Z", "scanmonth": "2018-01-31T23:00:00.000Z", "gender": "male", "therapy": "sda", "doa": "alive", "diagnosis": "shanghai", "mgmt": "unmethylated", "validated": true, "survival": 1, "karnofsky": 10, "ki67": 1 }, "Ex2": { "pseudonym": "asdsad", "yob": "2010-12-31T23:00:00.000Z", "scanmonth": "2018-02-28T23:00:00.000Z", "gender": "male", "therapy": "asd", "doa": "alive", "diagnosis": "shanghai", "mgmt": "unmethylated", "validated": true, "survival": 1, "karnofsky": 10, "ki67": 1 } }

Answer №1

My solution involved including the following line of code in my save function:

this.$forceUpdate()

While effective, I can't help but feel that this approach is somewhat crude.

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

Which specific graphing library does GitHub utilize for its Graphs section?

Which graphing library is utilized by GitHub on its Graphs tab? The graphs displayed at https://github.com/USER/REPOSITORY/graphs/commit-activity are visually appealing, detailed, and adaptable. If they are leveraging an open source javascript library fo ...

Issues with lazy loading in swiper.js when trying to display multiple images per slide

I recently tried using swiper.js and had success with the lazy loading demo. However, I encountered an issue where only one image per slide was showing up, despite wanting to display 4 images per slide. <div class="swiper-container"> <div cla ...

Vue.js Vuex unit test fails due to an error message indicating an unidentified getter in Vuex: "[vuex

I am currently testing my App.vue file and encountering a Vuex error with getters. It seems to be related to improperly defined getter properties, but I am struggling to find a solution. Any feedback would be appreciated. Error Log ERROR LOG: '[ ...

Unable to retrieve table header information when clicking on a table cell

My code is working perfectly, except for the fact that when I click on a cell, I cannot retrieve the table header text. Retrieving the row text works fine based on the code. If I use Object.keys(data) inside the alert function to retrieve the data, it give ...

JavaScript unable to remove cookie from system

I'm currently on an external website and attempting to use JavaScript to remove a cookie. Here's what I tried in the console: function deleteAllCookies() { var cookies = document.cookie.split(";"); for (var i = 0; i < cookies.length ...

Adjust the pagination page size based on the value in the Angular scope dynamically

My goal is to provide the user with the ability to adjust the number of rows displayed in a table. This feature is crucial for our web app, as it needs to be accessible on various devices and should allow users to customize their viewing experience to redu ...

What is the best way to determine the quantity of elements received from an ajax request?

Here's the method I am currently using to count the number of li elements returned from an AJAX call: $.post('@Url.Action("actionName", "controller")', function (data) { $('#notificationCounter').html($(data).find('li&a ...

Transferring data from a JavaScript variable to PHP using AJAX

I’m currently working through the tutorial at http://www.w3schools.com/php/php_ajax_database.asp and I think I have a good grasp of how it all operates. This is my code: PHP: <?php include('./db.php'); $PM = mysqli_query($con, "SELECT DIS ...

Generating table rows dynamically using functions

I am working on a table where I need to dynamically add or remove rows. Each row contains a hyperlink in the last column to delete the record. Sometimes, if the record is not found in the database, this can cause issues as new rows are added dynamically af ...

When attempting to dispatch in getServerSideProps, the State refuses to change. Could it be due to the Redux-Next-Wrapper?

I'm facing an issue where the Redux Store does not change when I dispatch in getServerSideProps. Even though I can see the changes in console log after dispatch, the store appears as an empty array when the page loads. Why are these changes not taking ...

What is the process for inserting a watermark onto an image as it is being retrieved from Firebase?

I am developing a React website where I need to implement a feature that adds a watermark to an image when it is retrieved from Firebase storage. Is there a way to apply a watermark while accessing the image from the storage? I have already looked into Ho ...

Using a loop to iterate through a multidimensional array in Node.js or JavaScript, creating additional data and adding new key-value pairs

Here is an array of objects showcasing different intents and results : var finalresult = [{ "Date": "Wed Jan 15 2020 00:00:00 GMT+0530 (India Standard Time)", "data": [{ "intent": "delivery", "result": [{ "h ...

What is the most effective way to transfer visitor hits information from an Express.js server to Next.js?

I've developed a basic next.js application with an express.js backend. What I'm aiming for is to have the server track hits every time a user visits the site and then send this hit count back to the next.js application. Check out my server.js cod ...

Filtering JSON objects in Vue when the API is only returning a limited number of items

Currently, I am retrieving a JSON Object from an API with a limit of 200. The process involves fetching the initial 200 like this: https://testapi.com/posts.json In our application, we have implemented pagination with 10 posts per page. When we reach pag ...

What are ways to identify if text includes a hyperlink?

Using Vue, I am trying to identify all the links within the text. For example, if my text is: Text: 'hello mate check this link' I would like for this text to appear as: 'hello mate check this link' ...

React: The peculiar contradiction of useEffect with eventHandler props

Having trouble with this specific example. The issue arises with an Input component that includes an onChange prop to manage internal data changes. Under normal circumstances, if the value is updated externally, the onChange prop does not trigger since t ...

Utilizing $asyncValidators in angularjs to implement error messages in the HTML: A guide

This is my first major form with validations and more. I've set up a Registration form and I'm utilizing ng-messages for validation. The issue arises when I have to check the username, whether it already exists in the JSON server we are using or ...

Retrieving embedded documents from Mongoose collections

I am currently facing challenges in caching friends from social media in the user's document. Initially, I attempted to clear out the existing friends cache and replace it with fresh data fetched from the social media platform. However, I encountered ...

Refresh a DIV using two SQL queries in forms

I am encountering an issue with updating a single div element using the results from two different forms on an HTML page. I want either form1 or form2 to display results in the same div element, and it should be updated with one line of content fetched fro ...

Is it possible to add items to a JS object that isn't an array?

Here is an example of the object I am working with: { "_id": "DEADBEEF", "_rev": "2-FEEDME", "name": "Jimmy Strawson", "link": "placeholder.txt", "entries": { "Foo": 0 } } To access this data in my JavaScript code, I use a $.getJSON call. ...