1. 程式人生 > >vue-cli 中 img 的 src 無法引入問題

vue-cli 中 img 的 src 無法引入問題

在這裡插入圖片描述
An error is reported as shown in the figure.

After consulting official documents, it turned out that there was no webpack problem, but another way was found.
在這裡插入圖片描述
First and foremost,putting your image‘s files in the public directory
在這裡插入圖片描述
In addition, you will need to first pass the base URL to your component in templates:

data () {
  return {
    baseUrl: process.env.BASE_URL
  }
}

Then:

<img :src="`${baseUrl}my-image.png`">