[Vuejs]-Vue.js computed property to parse/format data

0👍

Since this.building has no buildingID (thus, undefined), and there is no item in buildings that has undefined as the value for buildingID, it fails.

This is because the find method will return undefined when the condition couldn’t be satisfied.

The find() method returns the value of the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned.

MDN Reference

0👍

In the computed property you are passing the whole building rather than the id, whereas in your method (in find) you are comparing the ids.

You need to pass the building id to your method.

Also in your data you are declaring building as an object, and then in your computed property, you are asserting whether building equals New which is a string.

I would advise the first thing you have to do is rethink your data types and the flow of your data between the template, computed properties, methods and data.

Leave a comment