LoginSignup
1
2

More than 3 years have passed since last update.

assets の画像パスをpropsで受け取って表示する方法

Posted at

assets に格納した画像のパスを props で受け取って表示したかったのですが、なかなかうまくいかなくて調査に時間がかかってしまいました。
解決できたので備忘録です。

require を使う

▼失敗例

<img :src="image_src" alt=""/>

▼成功例

<img :src="require(`@/assets/${image_src}`)" alt=""/>

image_src は props のプロパティ

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2