Skip to content
Advertisement

Vue method not returning value

I’m currently working with Vue, I have a method that is suppose to return a string which is displayed in a <span>. When I console.log the value I’m able to get the correct value however is not being passed into the span tag.

JavaScript

From the above code snippet you can see that I am returning a value tag. return tag is suppose to return a string which I then pass into the following script tag.

JavaScript

The following line is not displaying anything ${ testOne(job, job.taxanomy, job.mainTag) } although I’m able to see the return string on the console.log. I’m using ${ } because I changed the delimeters from {{ }} to ${ }. enter image description here

Advertisement

Answer

You are not returning a value from testOne. You are returning a value from the callback passed to forEach, which is not the same thing.

You can use filter to filter jobs according to your condition and then return a value from the array.

JavaScript

I’m assuming that there is at least one result, which may not be the case.

Also your condition may yield more than one result, you should have a way of dealing with this case also.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement