The reactivity of Vuex mutation mutations may become compromised

state.js:

export default () => ({
  stepBarItems: [
    {
      title: 'Introductory Details',
      active: false,
      current: false
    },
    {
      title: 'Personal Information',
      active: false,
      current: false
    },
    {
      title: 'Travel Plans',
      active: false,
      current: false
    },
    {
      title: 'Payment Method',
      active: false,
      current: false
    },
    {
      title: 'Document Upload',
      active: false,
      current: false
    }
  ]
})

mutations.js:

export default {
  setCurrentStepBarItem(state) {
    const index = state.stepLevel - 1
    state.stepBarItems[index].active = true
    state.stepBarItems[index].current = true
  }
}

form.vue

  created() {
    this.$store.commit('visa/setCurrentStepBarItem')
  },

Issue arises as the mutation is not triggering reactivity in the application.

https://i.sstatic.net/60eon.png

https://i.sstatic.net/7abs0.png

In spite of changes to the state and using a getter to access stepBarItems, no updates are visible. What could be causing this discrepancy?

Answer №1

If you want to achieve the desired format without using active/current variables, you can utilize computed properties like in this example:

new Vue({
el: "#app",

data: () => ({
    stepBarItems: [
        'General Info',
        'Personal Details',
        'Travel Details',
        'Payment',
        'Upload Documents'
    ],
    stepLevel: 0
}),

computed: {
    computedStepBarItems() {
        return this.stepBarItems.map((item, index) => ({
            title: item,
            current: this.stepLevel === index,
            active: this.stepLevel >= index
        }))
    }
},

methods: {
    next() {
        this.stepLevel += 1
    },

    prev() {
        this.stepLevel -= 1
    }
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <pre>{{ computedStepBarItems }}</pre>
  <button @click="prev()">Prev</button>
  <button @click="next()">Next</button>
</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

Uh oh! We've encountered an issue: Unable to update headers once they have been sent

I am currently working with express and node.js My objective is to redirect users to /welcome when they visit /index and have a specific tracking code in the URL. The redirectBasedReferrer function handles the redirection based on the tracking code. inde ...

Utilizing JavaScript to trigger an email with PHP variables included

i am trying to pass a few php variables using a javascript trigger. Everything seems to be working with the variables, databases, and script but I am struggling with the PHP part. Here is my attempt at the PHP code, although it clearly has some issues. I ...

Having trouble changing the query string in the URL with Angular 4?

My search form includes various filters such as text inputs, checkboxes, and radio buttons. Whenever the user interacts with these filters, the query string in the URL needs to be updated. Consider the following scenario: http://example.com/search?myFilt ...

Showcasing only one item at a time in AngularJS 1.x with ng-repeat; by clicking on "next", the subsequent item will be displayed,

Currently, I am working on a quiz web application that requires displaying a total of 100 questions across 3 different tabs - Math, GK, and English. The questions are filtered using an Angular filter. However, I'm facing an issue where each tab is sho ...

Refreshing a Particular JavaScript File in Electron Upon Request

Lately, I've been working on an Electron app that involves storing data in a javascript file. The data needs to be decrypted when the user logs in and displayed, then encrypted again when the user logs out. While logged in, users can add new data to t ...

Troubleshooting Challenges with JSON and jQuery Encoding

Having an issue with displaying data from a JSON file using jQuery: { "nombre": "Jesús Ramírez", "edad": "25 Años", "imagen":"file.jpg" } Here's my code: JAVASCRIPT $.getJSON(file.json, function(data) { var name= data.nombre; ...

Issue with unresolved module in ESLint

Currently, I am utilizing the vss-web-extension-sdk in my project. To ensure the validity of my files, I have integrated ESLint along with eslint-plugin-import and eslint-import-resolver-typescript. import { WidgetSettings, WidgetStatus } from "TFS/Dashbo ...

Enhancing MEAN Stack Application by Updating Table Post Database Collection Modification

In my efforts to ensure that my table data remains synchronized with the database information, I have encountered an issue. Whenever Data Changes: $scope.changeStatus = function($event,label,status){ var target = $event.currentTarget; target ...

Reactive Components in Nuxt.js/Vue.js/Laravel 5.7 API respond dynamically to actions and mutations

Can you lend me a hand? I've tried various solutions but still can't figure this out. Currently, I have a Nuxtjs project integrated with a Laravel 5.7 API (using JWT Auth for authentication). Users are able to perform CRUD operations on posts wi ...

When executed on the node REPL, lodash.sortBy will update the lodash value

When I access the node REPL, the following happens: > _ = require('lodash'); > // it displays the whole lodash object > _.sortBy(['1234', '123'], function (element) { return element.length; }); > [ '123&apos ...

Generating a JavaScript object based on an array of keys

I'm currently grappling with a task that is proving to be quite challenging. I have a set of arrays structured like this: ['key1', 'key2', 'key3'] ['key1', 'key2', 'key4'] ['key1', ...

Vue getter attribute not defined

i received state pages from an api call const state = () => ({ info: [], pages: [] }) along with a Getter const getters = { // HomePage_Getters HomeAdvantages(state) { return state.pages.find((page) => (page.template = 'home' ...

Internet Explorer causing trouble with reliable Ajax dropdown selection

There are two drop-down lists on my website, where the options in one depend on the selection in the other. The Ajax code works perfectly fine in Chrome and Mozilla, but it's not functioning correctly in Internet Explorer (specifically IE9). I need so ...

My goal is to retrieve and print the duplicated values only once from an associative array

Given an associative array, I need to print all the department names without any repetitions. <h3>2. List out all department names</h3> <div class="all"> </div> Here is my JavaScript code: var employee=[{"firstName":"Zahir","last ...

Difficulty in retrieving a variable in JavaScript from an AJAX call

let bbb; let ma_category; ma_category = "Vocabulary"; $(document).ready(function() { $("#create_matching_activity").click(function(){ $.ajax({ type: "POST", url: "a_category_code.php?ma_category="+ma_category, ...

JavaScript for beginners: show a specified amount of search results and insert a loading indicator at the end

Currently, I have a website that retrieves data from my database using a PHP query. However, the issue I am facing is that there are over 300 entries in my database, resulting in an excessively long displayed page. My main question: How can I restrict ...

Attempting to condense an array of objects into a consolidated and combined array of objects

My array of objects is structured like this: dataArray = [ {Revenue: 5, Date: "2018-06-05T00:00:00", DateString: "6/5/2018"}, {Revenue: 10, Date: "2018-06-05T00:00:00", DateString: "6/5/2018"}, {Revenue: 5, Date: "2018-06-05T00:00:00", DateSt ...

There is a lag in the loading of css stylesheets

We created a single-page company website that utilizes three different stylesheets connected to the index.html. By clicking a button, users can switch between these stylesheets resulting in changes to colors, images, and text colors. However, Issue 1: The ...

AngularJS directive $destroy is a useful tool for managing the

My angular application has been configured with the use of ng-view. Within one specific view, there is a dynamically loaded component alongside the view itself. This component acts as a directive that compiles its contents to allow for further interaction ...

I am experiencing an issue where my Visual Studio Code extension is failing to display code correctly

Hey everyone, I'm a student and a beginner in Visual Studio code. Recently, I was working with Java Script and ran into an issue. Every time I tried to save my code by pressing Ctrl+S, it would automatically indent the code, causing problems in my ter ...