'Vue cli 3 project ,dynamic src in image path not working

I am referencing an image url in a vue component like

<img alt="Vue logo" src="~statics/reports/logo.png">

this works

but while trying

<img alt="Vue logo" :src="getURL()">


data() {
    return { imgPath: "~statics/reports/logo.png" };
  },

  methods: {

    getURL() {
        // 

      // console.log(path)
      return (this.imgPath)
    }
  },

it fails

My folder structure is enter image description here

In the first case the path is resolved to

http://localhost:8081/img/logo.82b9c7a5.png

and served automatically by the dev server

The path is not resolved in the second case it remains http://localhost:8081/~statics/reports/logo.png

I am using vue cli 3 generated default config for webpack .

I do not want to use relative paths for all images like ../images/ as it makes it more verbose. I have tried require(pathVariable) that too does not work Please help with resolving the img path when the url is dynamic ie asset name comes from server and i append a path in a method or computed and use :src dynamicbinding to serve it



Solution 1:[1]

For Vue 3 projects you can use the following:

<img src="./assets/logo.png" />

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abeyance