Javascript 使用:在模板上键入v-for
你知道如何在模板中使用密钥吗 我的示例代码Javascript 使用:在模板上键入v-for,javascript,vue.js,vuejs2,Javascript,Vue.js,Vuejs2,你知道如何在模板中使用密钥吗 我的示例代码 <template v-if="_hasDeposit" > <template v-for="(_item, key) in item.client.deposits" :key="key"> <td><p class="title">{{_item.balance_formatted}}</p
<template v-if="_hasDeposit" >
<template v-for="(_item, key) in item.client.deposits" :key="key">
<td><p class="title">{{_item.balance_formatted}}</p></td>
<td>
<amount-input :disabled="inputDisabled(item.id)
"@amountEncoded="amountEncoded($event,'deposit',_item.deposit_account_id)"
:account_info="_item"
:tabindex="tabIndex('loan',key)"
:add_class="errorAddClass(item.id,'deposit')"
>
</amount-input>
<div class="text-danger" v-if="hasInputError(item.id,'deposit',key)" >
{{inputErrorMessage(item.id,['amount','repayment_date'],'deposit',key)}}
</div>
</td>
</template>
</template>
{{{{u item.balance}
{{inputErrorMessage(item.id,['amount','returning\u date'],'deposit',key)}
错误是:无法键入。将键放在实数元素上。
但是在我的例子中,我需要它位于
中,对于的父项,您可以使用循环的键
变量,而无需将:key
属性设置到模板。但是,您可以为子
元素设置键,如本期中提到的本例中所示
因此,在你的情况下,它将是
<template v-if="_hasDeposit" >
<template v-for="(_item, key) in item.client.deposits">
<td :key="key + 'title'"><p class="title">{{_item.balance_formatted}}</p></td>
<td :key="key + 'input'">
<amount-input :disabled="inputDisabled(item.id)
"@amountEncoded="amountEncoded($event,'deposit',_item.deposit_account_id)"
:account_info="_item"
:tabindex="tabIndex('loan',key)"
:add_class="errorAddClass(item.id,'deposit')"
>
</amount-input>
<div class="text-danger" v-if="hasInputError(item.id,'deposit',key)" >
{{inputErrorMessage(item.id,['amount','repayment_date'],'deposit',key)}}
</div>
</td>
</template>
</template>
{{{{u item.balance}
{{inputErrorMessage(item.id,['amount','returning\u date'],'deposit',key)}
使用div而不是second temple.@Mr.perfecturist div不适用。这是一个表,如果用作它的父级,则会破坏表。谢谢。我以前试过这个,我认为它不起作用。因为我在我的应用程序中使用了黑色主题,文本也是黑色的。我以为它不起作用,但它还没有显示出来