Unable to utilize a computed property within the data section

I am working with an array in my data:

data () {
  return {
    steps: [
      {
        disabled: this.someCheck
      }
    ]
  }
}

Additionally, I have a computed property:

computed: {
  ...mapGetters({
    getFinishedSteps: 'jobFound/getFinishedSteps'
  }),

  someCheck () {
    let x = true
    for (const val of this.getFinishedSteps) {
      if (val === ('address_information' || 'contact_information' || 'financiel_information' || 'identity_information')) {
        x = false
      }
    }
    return x
  }
}

In the template section, I have included:

<ProgressContent
  v-for="(step, n) of steps"
  :key="n"
/>

To elaborate on the ProgressContent component:

props: {
  step: {
    type: Object,
    default: () => ({
      disabled: false
    })
  },
}

A challenge I am facing is passing the return value of the someCheck computed property into the disabled field in the data. However, when viewing the ProgressContent component, the disabled field appears to be empty.

Answer №1

Attempting to assign a computed value to a data property during initialization is not allowed. This would result in a non-reactive behavior, as the assignment would only happen once and not update when the computed value changes.

To address this issue, you can define steps as a computed property:

computed: {
  ...mapGetters({
    getFinishedSteps: 'jobFound/getFinishedSteps'
  }),
  someCheck () {
    // code for someCheck
  },
  steps() {
    return [{ disabled: this.someCheck }]
  }
}

Alternatively, you can utilize a watcher:

data() {
  return {
    steps: [{ disabled: null }]
  }
},
computed: {
  ...mapGetters({
    getFinishedSteps: 'jobFound/getFinishedSteps'
  }),
  someCheck () {
    // code for someCheck
  }
},
watch: {
  someCheck: {
    handler(newValue) {
      this.steps[0].disabled = newValue;
    },
    immediate: true
  }
},

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

Error encountered in Ionic app: array.push() is not a valid function

A situation arose in my application where I have a controller and factory set up. Inside the factory, there is an array that should hold IDs of certain elements. However, when attempting to push an element into the array, an error is triggered stating: ...

Is it possible to move between textboxes using arrow keys in HTML?

Is there a way to navigate through textboxes using arrow keys in HTML without relying on jQuery? Possibly utilizing JavaScript, HTML, CSS, or another method? Thank you for your help! <body> <form> <input type="text"&g ...

Tips for using ng-repeat in AngularJs to filter (key, value) pairs

I am trying to achieve the following: <div ng-controller="TestCtrl"> <div ng-repeat="(k,v) in items | filter:hasSecurityId"> {{k}} {{v.pos}} </div> </div> Code snippet for AngularJs: function TestCtrl($scope) { ...

Transforming JSON data into XML using Angular 7

It turns out the xml2js npm package I was using doesn't support converting JSON to XML, which is exactly what I need for my API that communicates with an application only accepting XML format. In my service file shipment.service.ts import { Injecta ...

Instructions on how to export an HTML table to Excel or PDF by including specific buttons using PHP or JavaScript

I created a table to display leave details of employees with sorting options from date to date. Now, I need to include buttons for exporting the data to Excel and PDF formats. Check out the code below: <form name="filter" method="POST"> <in ...

The submission of the Ajax form isn't functioning as expected

I have created a feedback form with an image submit button instead of the regular HTML submit button. When I try to submit the form, the "data:" value always returns as NULL. Can you help me identify the issue in my code? Here is the code snippet: The FOR ...

How can I update an image source using JavaScript in a Django project?

Is it possible to dynamically change the image src using onclick without relying on hard paths or Django template tags? I have concerns that this may not be best practice. How can I implement a method to inject/change the ""{% static 'indv_proj&b ...

Modifying JavaScript prototypes on the fly can lead to troublesome issues

My curiosity has been piqued by the concept of dynamically changing a constructor's prototype in JavaScript, leading me to the findings above. It appears that an already constructed instance does not inherit the properties of the newly changed protot ...

Testing an Express application using Jenkins

After spending hours searching for a way to execute my Mocha unit tests in Jenkins for my Express JS application, I am still struggling to find a solution. While writing the tests themselves is relatively easy, integrating them with my app has proven to b ...

Transforming seconds into years, months, weeks, days, hours, minutes, and seconds

Can anyone help me modify Andris’ solution from this post: Convert seconds to days, hours, minutes and seconds to also include years, months, and weeks? I am currently running this code: getDateStrings() { console.log(req_creation_date); const toda ...

Tips for Resizing and Reviving Divs with jQuery

I have recently ventured into the world of web development to assist a family member with their website. My knowledge and experience are limited, but I am facing an interesting challenge. I am trying to manipulate certain divs as users scroll down the page ...

Choosing a radio button based on the stored value within a variable

When transferring a variable (active) from my route to EJS, I initially found it easy to simply display its value: <!-- Active Text Input--> <div class="form-outline mb-4"> <label for="active" class="form-label">Active</label> ...

Tips for implementing validation in JavaScript

I'm brand new to learning Javascript. Recently, I created a template for a login page and it's working perfectly fine. However, I am struggling with setting up validation and navigation. My goal is to redirect the user to another page if their us ...

NodeJS and ExpressJS fail to redirect to the main landing page

I am currently developing a shopping cart application using nodejs/expressjs. I have encountered an issue with redirecting back to the homepage ('/') after the user submits their credentials during sign up. Despite my search for relevant articles ...

VueJs fails to update data in certain situations

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <div class="container" id="app"> <table> <tr v-for="res in results" > <td> <input :id=res.id :value=res.LinkTitle > </td> ...

utilizing the JavaScript SDK to send alerts to a user's friends on Facebook

I am attempting to send a notification to a user's friend using the JS SDK on a Facebook canvas app, but I'm encountering this error in the console: POST https://graph.facebook.com/16542203957691/notifications? 400 (OK) jquery.min.js:140 c.exten ...

Encountering a "SyntaxError: Unexpected token '/' in... index.ejs while compiling ejs" issue following the recent npm package updates

After upgrading EJS from version 2.7.4 to 3.1.5 along with some other packages in my project, I am encountering a problem where I can no longer access any of the webpages. Instead, an error is being thrown on every page. Additionally, after the update, I s ...

How can you prevent videos from constantly reloading when the same source is used in multiple components or pages?

How can we enhance loading performance in Javascript, React, or Next JS when utilizing the same video resource across various components on different pages of the website to prevent unnecessary reloading? Is there a method to store loaded videos in memor ...

Error: Cannot execute products.map in React JS because it is not a function

I'm encountering a TypeError: products.map is not a function error while attempting to iterate or map through the objects in my current state. I am fetching products from an API and storing them in state with the intention of displaying these objects. ...

Navigating to an Element in React's Document Object Model

Using React 16.4, I am faced with the need to scroll to a specific DOM element within the application. Since refs are deprecated in React, I am on a quest to find the most elegant solution for this problem. However, I find it challenging to come up with a ...