Dies ist eine alte Version des Dokuments!
LU05.A17 - v-for with 2-dimensional-arrays and v-if
Prerequisites
- Work type: Individual
- Means of aid: only teaching materials, no websearch, no use of ai.
- Timeframe: 15 Minutes
- Expected result: A Vue script that uses the v-for directive combined with v-if
Learning objectives
- Displying an multidimensional array using v-for and v-if
Source
This is the result of the previous assignment. Copy + paste the content to your W3School-Workingspace.
Assignment 1
After successfully being able to manage 2-dimensional-arrays with the v-for directive, it is time to take next challenge: the combined usage of v-for and v-if.
Though the assigment is to dispay the pictures only, when they are likes. For that we need to check the status, it they are OK we display the image of the dish, if they are NOK we simply give out the name and the statu of the dish, but no image of it.
- Go to the link to the task mentioned in the source and save it with the appropriate name in your W3School workspace.
- Change the first x to z and observe what happens.
Assignment 2
It can happen, that besides the image, we also want to display the description of our products on our website. That means, that it is time for some elbow grease. We want to handle a multi-dimensional array. Have fun with the challenge.
- E.g.: Multidimensional arrays are manages as follows: manyBeaches: [{name: 'Sunset', url: './public/beach1.jpg', stat: 'Nice'}, … ]
- Name the already existing entries: img
- As we just changed the dimension of our array, we need to adjust the call in the v-for-part from z to z.img.
- Add a <figure>-tag just after the div tag, and resettle the v-for in it. The end of the
- Execute your script. If everthing was done properly you will see the images as before.
- Now add a comment-column to you food-list (array). If you like it: OK. If not: NOK
- Display the comment with a figcaption-tag by using z.comm within a double bracket {{}}.
- Execute your script. If everthing was done properly you will see the images as before AND the comment below the image.
- Do the same with the names of the dishes.
- Execute your script. If everthing was done properly you will see the images as before, the status, but now also the names of the dishes.
- Comment you script accordingly an save it.