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

The error message in React Hook Form states that the handleSubmit function is not recognized

I'm facing an issue with using react-hook-form for capturing user input. React keeps throwing an error that says "handleSubmit is not a function". Any suggestions on how to resolve this would be highly appreciated. Here's the code snippet I&apos ...

Adjust text at multiple positions using Javascript

I am working on parsing a complex query and developing a tool using the following sample: var str =" SELECT 'Capital Return' AS Portfolio_Classification , '(Gross)' AS Portfolio_Type , '0.21%& ...

How to remove the black border on a material-ui button

I am currently working with the material-ui datepicker and buttons. Whenever I click on the datepicker icon to select a date or any of the buttons, I notice a black border appearing. How can I remove this black border from the design? ...

Place a list with scrolling and overflow features side by side

Having trouble getting my headers to scroll with overflow auto and white-space nowrap. Can't figure out why it's not working. I want to create hyperlinks within headers to link to specific parts of the website. I have the code for hyperlinking s ...

Using Laravel 5.6 to capture and validate user-inputted dates prior to storing them in the database

Users are able to input a date into a form and submit it. Unfortunately, the validation rules seem to be failing. 'reportedDate'=>'required|date|date_format:Y-m-d' ​ ​ <div class="form-group"> <label for="reported ...

Best locations for placing files when integrating Javascript into Wordpress

I have been struggling to make JavaScript work and determine the correct location to place the files. After attempting various methods, I am now wondering what the most logical approach would be. Despite spending a week on this task, the lack of a tutoria ...

Featuring a visual arrangement of categorized images with AngularJS for an interactive display

As I work on developing a web application with Angular, my goal is to create a grid layout that organizes items by category. Each row will represent a different category. Below is an example of the code structure I have in place: <ion-item ng-repeat="i ...

What is the best way to activate matching dates within the rangeselector data?

A datepicker has been integrated into a highchart in the following manner. $(function() { $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function(data) { // Create the chart $('#co ...

What is the reasoning behind CoffeeScript automatically adding a function when extending an Object?

I'm currently working on a helper method to identify the intersection of two hashes/Objects in this manner... Object::intersect = (obj)-> t = {} t[k] = @[k] for k of obj t x = { a: 1, b: 2, c: 3 } w = { a: true, b: 3 } x.intersect(w) #=> ...

Utilizing a created variable within the alert function: A guide

In order to display error messages in my app, I have created the following code: function createTimer(): void { if (!timer.start) { Alert.alert(strings.reminders['date-required']) return; } else if (!timer.end) { Alert.alert(strin ...

Incorporating external CSS and JS files into your WordPress website

Hello, I am unfamiliar with the Wordpress framework and I am seeking guidance on how to add an external CSS and JS file to my Wordpress page. I have successfully created a new page, but would like to incorporate a CSS and JS file into it. Would creating a ...

Manipulating rows [using an input field] within a table

As someone new to JavaScript, I tried my hand at coding the following piece after tweaking a tutorial I stumbled upon. The aim was to have rows with input fields added and removed within a table, but unfortunately, nothing happens when running the code. ...

Tips for transferring PHP variable from a drop down menu

Hello, I am currently working on creating a dropdown menu using the <select> tag. My goal is to have it so that when someone clicks on one of the options in the dropdown, a new window opens. Additionally, I want the PHP variable from the main page to ...

Error code E401 is being encountered with npm, indicating either an incorrect password has been provided or the

My Node version is 10.15.0 and my NPM version is currently at 6.8.4. After updating npm to 14.16.0 and node to 7.6.2, I encountered the following error - npm ERR! code E401 npm ERR! Incorrect or missing password. npm ERR! If you were trying to log in, ...

How to add an OnClick listener to a cell element in a table built with the Tan

I am currently working on a project using React and trying to implement a table. I want to show an alert when a header cell in the table is clicked, displaying some information. However, I have been struggling to find assistance on adding a click listener ...

Uninterrupted jQuery AJAX calls

I have a scenario where I need to periodically update an image on my view using ajax every 10 seconds. Any suggestions on how I can achieve this? Appreciate the help. ...

Incorporating a rigged and animated asset into a preexisting scene using Three.js

Currently, I'm developing a browser app similar to Tamagotchi using three.js. However, I've hit a roadblock while trying to implement a hand that can pet the avatar when clicked. The Hand is a rigged Blender model with two animations: idle and p ...

collaborate and coordinate a territory among various components on a map

I'm currently working with an array of elements that are being drawn on a canvas. export function useCanvas(){ const canvasRef = useRef(null); const [ elements, setElements] = useState([]); const [ isHover, setIsHover] = useState(false); ...

The `tailwind.min.css` file takes precedence over `tailwind.css` in my Nuxt

Having trouble configuring Tailwind to use a custom font without it overriding the tailwind.css file and not displaying the changes? https://i.stack.imgur.com/ExDCL.png Check out my files below. // tailwind.config.js const defaultTheme = require('ta ...

Ways to focus on a specific div using JavaScript

I am attempting to create a 'snow' effect on the background of a particular div with a red border. Here is the code, but you can also view it here: <!-- language: lang-js --> var width = getWidth(); var height = getH ...