Instruct Vue to scan through a directory full of images without altering the filenames of the images

I came up with a method to instruct Vue to search in a file and assign images to the corresponding number of cards. So far, it's working perfectly.

However, I'm curious if there is a more efficient way to achieve this. The current drawback is that you have to rename your images sequentially (e.g., 1.png, 2.png, 3.png, etc.), which is not ideal for SEO purposes. It can also be frustrating if you need to add or remove images.

While this issue isn't a deal-breaker, I would prefer not to compromise my SEO ranking potential.

Below is the code snippet:

<v-container fluid>
            <v-row>
              <v-col
                v-for="n in 38"
                :key="n"
                class="d-flex child-flex"
                cols="4"
              >
                <v-lazy
                  :options="{
                    threshold: 0.5,
                  }"
                  transition="fade-transition"
                >
                  <v-card elevation="8" shaped draggable="false" class="d-flex">
                    <v-img
                      :src="require('@/assets/skillsLogo/' + n + '.png')"
                      :lazy-src="require('@/assets/skillsLogo/' + n + '.png')"
                      class="grey lighten-4"
                      aspect-ratio="3"
                    >
                      <template v-slot:placeholder>
                        <v-row
                          class="fill-height ma-0"
                          align="center"
                          justify="center"
                        >
                          <v-progress-circular
                            indeterminate
                            color="grey lighten-5"
                          ></v-progress-circular>
                        </v-row>
                      </template>
                    </v-img>
                  </v-card>
                </v-lazy>
              </v-col>
            </v-row>
          </v-container>

Thank you for any suggestions.

Answer №1

photos.js

const photoContext = require.context("@/assets/photoGallery/", false, /\.jpg$/);
const photosArray = photoContext.keys().map(photoContext);

export default photosArray;

Documentation

Component:

<script>
import photosArray from "./photos.js";

export default {
  data() {
    return {
      images: photosArray,
    };
  },
};
</script>

Loop through the images array in your template...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

This code encountered an Uncaught SyntaxError due to an invalid or unexpected token

Hey there, I've been struggling with an Uncaught SyntaxError: Invalid or unexpected token issue whenever I try to click on the edit or delete button. Can someone please help me figure out what's wrong with this code? I've spent hours looking ...

Updating the text of GridView headers

In order to meet the requirements, the grid should have AutoGenerateColumns = true with no use of TemplateField. Only manipulation of the .cs file is allowed. Key requirements include: The grid should be autogenerated Sorting and paging features are perm ...

Div containing scrollable content with overlaid child element

I am facing an issue with a scrollable div that contains a table, where I am trying to append a loader component as a child to cover the div when it's scrolled. However, the loader only covers the initial size of the div. Here is an example similar t ...

What is the best way to include a second (concealed) value in a cell using datatables

Query: How can I send specific cell values to a controller using POST method, where one value is visible and the other is hidden? For instance, each cell contains both Time and Date data but only the Time is displayed in the datatable. I need to post both ...

What is the best way to apply hover effects to all links except the one being hovered over, using a combination of javascript, jquery,

While browsing the web, I came across a fascinating hover effect that I'm eager to replicate in a website's navigation bar. This effect doesn't just change the link you hover over, but it alters every other link in a unique way. When hoverin ...

Using ASP.NET MVC to map FormData with an array to a model class

I am currently facing an issue with mapping a list of objects in a FormData to my ASP.NET MVC Model class at the controller. I have successfully sent the FormData over to the server-side, but I am unable to bind any value. Can someone provide guidance on h ...

Error: Unable to execute this.getOptions as a function

I encountered a peculiar error after installing Bootstrap. The error message is displayed below. Despite attempting to resolve the issue by uninstalling less-loader and then installing [email protected], as suggested online, there was no improvement. I a ...

Save a specific collection of divs from a webpage as a PDF or Word document

Could the following scenario be achievable? Imagine a webpage containing a series of div elements with unique IDs or classes. Inside each div, there is a title (possibly an h1 tag) and some additional content. Is it possible to create a selection list of t ...

Troubleshooting error 1045: User 'root'@'localhost' denied access

When trying to connect a MySQL database to my NODEJS application, I keep encountering an error every time I start the server. The error message reads "Access denied for user 'root'@'localhost' using password YES, error number 1045." De ...

"Fixing the Vertical Order of Divs with Jquery: A Step-by-

Before I completely lose my mind, I need some help with a coding issue. Right now, I have two initial divs displayed. The user should be able to add these divs below the original ones as many times as they want, or remove them if needed. I've been att ...

What is the best way to implement rotation functionality for mobile devices when dragging on a 3D globe using D3.js and an HTML canvas?

I have been experimenting with the techniques demonstrated in Learning D3.js 5 mapping to create a 3D globe and incorporate zoom and rotation functionalities for map navigation. Here is the function that handles both zooming and dragging on devices equipp ...

Ways to monitor the status of a server request using jQuery (ajax)?

I am currently working on a PHP application that involves users submitting forms to the server via ajax (jQuery). The server needs to insert a large number of records into a MySQL database, which may take some time due to various calculations. My question ...

Can you explain the functioning of knockout container less syntax? (does it have any drawbacks?)

There are numerous instances and examples of using knockout ContainerLess syntax, although I find it challenging to locate proper documentation from their site. Initially, my question was "is it evil?" but upon realizing my lack of understanding on how it ...

Issues accessing my Facebook account due to domain problems

I have developed an HTML5 game that I am currently running in my web browser. My objective is to integrate Facebook login functionality, so I followed a tutorial and replaced the necessary information with my App ID. However, upon running it, an error mes ...

Is there a way to update the state for a specific location on a map?

I have a requirement to update the quantity of a product by using setCount. let [product.quantity, setCount] = useState(product.quantity); Implementing increment and decrement functions for product.quantity const increaseQuantity = () => { setCoun ...

What is the best way to calculate the total number of results using ajax?

Encountering an issue with the total count of ajax search results. Getting an error message "Method Illuminate\Database\Eloquent\Collection::total does not exist." when using directives, for example: <div class="searched-item"&g ...

Guide on downloading jsreport in .Net using C# without opening it

I am using JS Report to generate a file and save it in the root directory. However, I want the file to be downloaded directly instead of opening for viewing. var header = await _jsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "H ...

I am unable to view the map on my webpage. This issue only arises when I apply a CSS style to it

Hey there! I'm having trouble displaying a map on my website. For some reason, the map is not showing up even after updating the Google secret key in my code: <?php session_start(); include '../../WSweb/serv.php'; if(isset($_SESSION[&a ...

Refresh the homepage of a website using React Router by clicking on the site's logo from within the Home component

In most cases, when you click on a website's logo while on the homepage, it typically reloads the page. However, with React, clicking on the logo while already on the Home component does not trigger a reload. Is there a way to work around this issue? ...

What is the best way to calculate the duration of a .wav file stored locally using JavaScript?

Can you help me figure out how to determine the duration (in milliseconds) of a .wav file using JavaScript for a GreaseMonkey Script? The main challenges I'm encountering are: 1) Accessing local files 2) Retrieving the length of the wav file ...