gpt4 book ai didi

vue.js - Vue for 模板内循环

转载 作者:行者123 更新时间:2023-12-02 03:28:32 26 4
gpt4 key购买 nike

我有一个 Vue 模板,它接收 json 字符串作为数据:

<component data="{{ object.toJson() }}"></component>

对象由名称和字符串数组组成。我现在有这个在我的

<template>    
<ul>
<li v-for="url in object.data['urls']">{{ url }}</li>
</ul>
</template>

然而,这在我的 linter 上给出了错误,我想知道为什么。这与文档中发布的 Vue 示例完全相同。

error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key

最佳答案

您可以向元素添加索引,如下所示:

<template>    
<ul>
<li v-for="(url, index) in object.data['urls']" :key="index">{{ url }}</li>
</ul>
</template>

关于vue.js - Vue for 模板内循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52517256/

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