1

I have computed property like this:

  display() {
     return this.labs.map(function(x, i) {
        return [x, this.plotDt[i]];
      });
    }

It receives the data as props:

  props: ["plotDt", "labs"],

Which are arrays of same lenght (I input two arrays: [a,b,c] [1,2,3] and expect to get mapped array: [[a,1],[b,2],[c,3]]

However somehow it does not work and when I check in VueTools I get message: "error during evaluation" I dont really know what can be wrong in this case.

3
  • 1
    is [a,b,c] actually ['a','b','c']? are they both the same length? Commented Mar 19, 2020 at 11:23
  • you might look at: forum.vuejs.org/t/missing-error-details-for-computed-properties/… Commented Mar 19, 2020 at 11:27
  • @depperm Yes they are it works normally when I set those arrays in console and run that mapping method Commented Mar 19, 2020 at 11:39

2 Answers 2

1

A possible workaround could be:

 display() {
     const vm = this;
     return this.labs.map(function(x, i) {
        return [x, vm.plotDt[i]];
      });
    }

And it is also possible that you need to go for method instead of computed. Mind sharing code pen?

Sign up to request clarification or add additional context in comments.

2 Comments

Do you have any resource that deals with this case? Or did you just thought of this on the spot?
This in function is not related to vue instance probably, so it is just my thoughts.
1

this won't have scope inside the function unless used the arrow function or bind this with the map

The issue can be solved either like

display() {
 return this.labs.map((x, i)=> {
    return [x, this.plotDt[i]];
 });
}

or

display() {
 return this.labs.map(function(x, i) {
    return [x, this.plotDt[i]];
  },this);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.