Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trializzy goldman
12,542 PointsWhy do we have to use a Parameters in the function?
When using v-for to loop through an array of objects why do i have to add a parameter to the method to let the method know which item in the loop we are targeting?
Why wont this
work in the function?i.e.this.media.showDetail = !this.media.showDetail
?
1 Answer
S L
31,336 PointsI had the same question for a moment,
this.media.showDetail = !this.media.showDetail
would not work because "this" would reference to the "app" object and its data which has two data parameters - "title" and "mediaList". So this keyword can only be used to update "this.title" and "this.mediaList".
Since mediaList is an array of "media" objects, the "toggleDetails" method needs to know which one to update - so this is why parameter is required.