【问题标题】:VueJS use v-for variable as attribute valueVueJS 使用 v-for 变量作为属性值
【发布时间】:2018-01-22 10:35:37
【问题描述】:

我有一个迭代循环,它在对象数组上使用 v-for,然后呈现一个 html li 项目

<li class="block" v-for="(section, key) in sectionDetails">
    <a href="#" tabindex="{{ key }}">Item {{ key }}</a>
</li>

这里的问题是tabindex属性中的key没有被渲染,被渲染的是{{ key }}

如何获取key 的值以用于tabindex?我也试过了,:tabindex 但这给了我一个 Javascript 错误。

【问题讨论】:

    标签: vue.js tabindex v-for


    【解决方案1】:

    Interpolation within attributes is not valid in Vue v2.

    您需要将tabindex 属性绑定到key,如下所示:

    <a href="#" :tabindex="key">Item {{ key }}</a>
    

    Here's a working fiddle.

    【讨论】:

      猜你喜欢
      • 2020-01-18
      • 1970-01-01
      • 2017-08-31
      • 1970-01-01
      • 2020-09-08
      • 1970-01-01
      • 2020-12-14
      • 2023-03-08
      相关资源
      最近更新 更多