Dies ist eine alte Version des Dokuments!


LU05.A16 - v-for list with 2-dimensional arrays

  • Work type: Individual
  • Means of aid: only teaching materials, no websearch, no use of ai.
  • Timeframe: 20 Minutes
  • Expected result: A Vue script that uses the v-for directive
  1. Be able to explain the objective of v-for
  2. Display the index and corresponding array entry using v-for.
  3. Display array elements and the corresponding images with v-for.

It can happen, that we need not only to display the images of our products, but want also to provide additional information to them. That invariably leads to having to have handle two or more arrays in our source code.

  1. Click on the link above with the source and save it with the appropriate name in your W3School workspace.
  2. Change within the v-for the x to z.
  3. Execute your script –> The images will will disappear. Why?
  4. Then change x within the <figcaption> from x to a z –> The images will appear again. Why?
  5. Note down for what the first respectively the second usage of x/z stands for.

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. For more information consult the following link: multi-dimensional arrays

  1. 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, as we are using a multi-dimensional arrray and must therefore define which column we actually want to display.
  2. Execute your script. If everything was done properly you will see the content as before.
  3. Add a column comm-column with comments to you food-list (array) in the script part.
    • If you like it: OK.
    • If not: NOK
  4. Display the comm-entries after the name of the dish by using z.comm
  5. Execute your script. If everything was done properly you will see the images as before AND the comment below the image.
  6. Comment your script accordingly an save it.
English German

Volkan Demir

  • en/modul/m291/learningunits/lu05/aufgaben/16.1743082622.txt.gz
  • Zuletzt geändert: 2025/03/27 14:37
  • von vdemir