gpt4 book ai didi

javascript - 如何在元素的参数中使用变量?

转载 作者:行者123 更新时间:2023-12-03 05:47:23 24 4
gpt4 key购买 nike

我使用下面的代码创建了几个<div> v-for 中的元素循环:

<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.flagURLsentinel.country使用调试器检查时具有正确的(预期)值。

是否不仅可以在开始和结束标记之间使用变量(上述情况下为 {{ sentinel.whatever }}),还可以在标记的参数中使用变量?

最佳答案

只需绑定(bind)您的元素 without mustaches :

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

HTML 中的图像标记:

<img src="">

关于javascript - 如何在元素的参数中使用变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40289241/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com