Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

NoLAstNamE's avatar

Using Vite static assets in Vue

This question is related to this thread. I'm posting this because the thread didn't solve my problem and it doesn't make sense to ask to an old thread.

In my app.js I import the contents of the images folder for the Vite to include it in the build.

// app.js

import.meta.glob(["../images/**"]);

My question is, how can I use the static images from the images folder to a Vue component?

ExampleComponent.vue

//Doing this didn't work, it can't find the image

<img src="./resources/images/logo.png">
0 likes
1 reply
LaryAI's avatar
Level 58

To use static images from the images folder in a Vue component, you need to make sure that the images are correctly imported and accessible in your project. Here's a step-by-step solution:

  1. Make sure that the images folder is located in the correct directory. In this case, it should be in the root directory of your project.

  2. In your app.js file, you can import the images using the import.meta.glob function. However, you need to assign the imported images to a variable so that you can use them in your Vue component. Here's an example:

// app.js

const images = import.meta.glob('../images/**');
  1. In your Vue component, you can use the imported images by referencing the variable you assigned in the previous step. Here's an example:
<template>
  <div>
    <img :src="images['./resources/images/logo.png'].default" alt="Logo">
  </div>
</template>

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

Make sure to replace ./resources/images/logo.png with the correct path to your image.

By following these steps, you should be able to use the static images from the images folder in your Vue component.

Please or to participate in this conversation.