Coding Challenge: Using the Nuxt Image Component
Create a project using the Nuxt image.
We'll cover the following
Problem statement
In this challenge, create a Nuxt project to loop over and display images using the NuxtImage
component. Create a function to handle toggling a border on the selected image when clicked. The index.vue
file has been created, which includes an array of three images to loop over.
Complete the project by following the steps below:
Add the
NuxtImage
component inside the<li>
section, which loops over the images array.Add the following attributes to
NuxtImage
:Display each image by setting the
:src
attribute.Call the
handleImageClicked
function when clicked and pass theimage
as an argument.Set the
width
of the image to 200 px.Set the
quality
to 80%.
Complete the
handleImageClicked
function:If the conditional statement is true, set the
selectedImage
to the value ofnull
.If the conditional statement is false, set the
selectedImage
to the value of theimage
.
Add a dynamic
:style
attribute toNuxtImage
. Then, use it to set a2px
border if the image has been clicked.
Your output should look like this:
Get hands-on with 1400+ tech skills courses.