2016-10-27 7 views
0

私はv-forループで数<div>要素を作成するために、次のコードを使用します。要素のパラメータで変数を使用するにはどうすればよいですか?

<div class="row" v-for="sentinel in sentinels"> 
    <div class="cell date">{{ sentinel.when }}</div> 
    <div class="cell city">{{ sentinel.city }}</div> 
</div> 

それは完璧に動作します。

私は今<img>要素でこれを拡張したい:

<div class="row" v-for="sentinel in sentinels"> 
    <div class="cell date">{{ sentinel.when }}</div> 
    <div class="cell city">{{ sentinel.city }}</div> 
    <div class="cell country"><img src={{ sentinel.flagURL }} title={{ sentinel.country }}></div> 
</div> 

これはコンソールでUncaught Error: Error parsing template:(…)エラーで失敗します。

sentinel.flagURLおよびsentinel.countryは、デバッガで確認するときに正しい(期待される)値を持っています。

開始タグと終了タグの間だけでなく、タグのパラメータにも変数(上記の場合は{{ sentinel.whatever }})を使用できますか? HTMLで

<div class="cell country"><img :src="sentinel.flagURL" :title="sentinel.country"></div> 

画像タグ:

+0

https://vuejs.org/guide/syntax.html#Attributes – epascarello

+0

@epascarello:ありがとうございました。私は受け入れられた答えにあなたのリンクを編集しました。 – WoJ

答えて

関連する問題