1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Nuxt】GETパラメータによってimgタグのsrc属性を動的に変更する

1
Posted at

はじめに

Nuxt.jsでGETのクエリで取得したパラメータの値によって変えようとして少しハマったので備忘録として投稿する。あくまでも一つの方法なので、参考程度にお願いします。

方法

http://localhost/result?id=ABC123のようにidのGETのクエリによって切り替えることを例に説明する。
以下のようにsrcをバインドする。バッククオートを用いることで評価式の結果を文字列としてそのまま書き出してくれる。また、$route.query.id。

<img :src="`http://localhost/${$route.query.id}.jpg`"/>

このようにすると以下のように変換してくれる。

<img :src="`http://localhost/ABC123.jpg`"/>
1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?