fix: add v-bind:key in all v-for

This commit is contained in:
Clark Du 2017-11-26 21:40:57 +08:00
parent 2ef69d47b1
commit 7fcbd5aa3b
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9
13 changed files with 18 additions and 14 deletions

View File

@ -3,7 +3,7 @@
<div class="container"> <div class="container">
<h1>Blog</h1> <h1>Blog</h1>
<ul> <ul>
<li v-for="post in posts"> <li v-for="(post, index) in posts" :key="index">
<nuxt-link :to="{ name: 'posts-id', params: { id: post.id } }">{{ post.title }}</nuxt-link> <nuxt-link :to="{ name: 'posts-id', params: { id: post.id } }">{{ post.title }}</nuxt-link>
</li> </li>
</ul> </ul>

View File

@ -2,7 +2,7 @@
<div class="container"> <div class="container">
<h2>Users</h2> <h2>Users</h2>
<ul class="users"> <ul class="users">
<li v-for="user in users"> <li v-for="user in users" :key="user.id">
<nuxt-link :to="'/users/'+user.id">{{ user.name }}</nuxt-link> <nuxt-link :to="'/users/'+user.id">{{ user.name }}</nuxt-link>
</li> </li>
</ul> </ul>

View File

@ -1,6 +1,6 @@
<template> <template>
<ul> <ul>
<li v-for="visit in visits"><i>{{ visit.date | hours }}</i> - {{ visit.path }}</li> <li v-for="(visit, index) in visits" :key="index"><i>{{ visit.date | hours }}</i> - {{ visit.path }}</li>
</ul> </ul>
</template> </template>

View File

@ -4,7 +4,9 @@
<pre>{{ userAgent }}</pre> <pre>{{ userAgent }}</pre>
<ul> <ul>
<li><nuxt-link to="/">Home</nuxt-link></li> <li><nuxt-link to="/">Home</nuxt-link></li>
<li v-for="slug in slugs"><nuxt-link :to="{ name: 'slug', params: { slug } }">{{ slug }}</nuxt-link></li> <li v-for="(slug, index) in slugs" :key="index">
<nuxt-link :to="{ name: 'slug', params: { slug } }">{{ slug }}</nuxt-link>
</li>
</ul> </ul>
</div> </div>
</template> </template>

View File

@ -3,7 +3,7 @@
<div class="left"> <div class="left">
<h2><nuxt-link to="/">Players</nuxt-link></h2> <h2><nuxt-link to="/">Players</nuxt-link></h2>
<ul class="players"> <ul class="players">
<li v-for="user in users"> <li v-for="user in users" :key="user.id">
<nuxt-link :to="'/'+user.id">{{ user.name }}</nuxt-link> <nuxt-link :to="'/'+user.id">{{ user.name }}</nuxt-link>
</li> </li>
</ul> </ul>

View File

@ -6,7 +6,7 @@
<nuxt-link v-if="page < totalPages" :to="'?page=' + (page + 1)">Next &gt;</nuxt-link> <nuxt-link v-if="page < totalPages" :to="'?page=' + (page + 1)">Next &gt;</nuxt-link>
<a v-else class="disabled">Next &gt;</a> <a v-else class="disabled">Next &gt;</a>
<ul> <ul>
<li v-for="user in users"> <li v-for="user in users" :key="user.id">
<img :src="user.avatar" class="avatar" /> <img :src="user.avatar" class="avatar" />
<span>{{ user.first_name }} {{ user.last_name }}</span> <span>{{ user.first_name }} {{ user.last_name }}</span>
</li> </li>

View File

@ -6,7 +6,7 @@
{{selected}} {{selected}}
</div> </div>
<div class="flex flex-wrap ph2 justify-between bg-white-80"> <div class="flex flex-wrap ph2 justify-between bg-white-80">
<div v-for="person in people"> <div v-for="person in people" :key="person.id">
<Card :person="person"></Card> <Card :person="person"></Card>
</div> </div>
</div> </div>

View File

@ -2,7 +2,7 @@
<div> <div>
<h3>Cars</h3> <h3>Cars</h3>
<ul> <ul>
<li v-for="car in allCars"> <li v-for="car in allCars" :key="car.id">
<nuxt-link :to="`car/${car.id}`"> <nuxt-link :to="`car/${car.id}`">
{{ car.year }} {{ car.make }} {{ car.model }} {{ car.year }} {{ car.make }} {{ car.model }}
</nuxt-link> </nuxt-link>

View File

@ -2,7 +2,7 @@
<div> <div>
<h2>Todos</h2> <h2>Todos</h2>
<ul> <ul>
<li v-for="todo in todos"> <li v-for="(todo, index) in todos" :key="index">
<input type="checkbox" :checked="todo.done" @change="toggle(todo)"> <input type="checkbox" :checked="todo.done" @change="toggle(todo)">
<span :class="{ done: todo.done }">{{ todo.text }}</span> <span :class="{ done: todo.done }">{{ todo.text }}</span>
</li> </li>

View File

@ -2,13 +2,13 @@
<div> <div>
<h2>Articles</h2> <h2>Articles</h2>
<ul> <ul>
<li v-for="article in articles"> <li v-for="(article, index) in articles" :key="index">
<span>{{article}}</span> <span>{{article}}</span>
</li> </li>
</ul> </ul>
<h2>Comments <small>(nested under articles)</small></h2> <h2>Comments <small>(nested under articles)</small></h2>
<ul> <ul>
<li v-for="comment in comments"> <li v-for="(comment, index) in comments" :key="index">
<span>{{comment}}</span> <span>{{comment}}</span>
</li> </li>
</ul> </ul>

View File

@ -8,7 +8,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="(value, key) in cookies"> <tr v-for="(value, key) in cookies" :key="key">
<td>{{ key }}</td> <td>{{ key }}</td>
<td>{{ value }}</td> <td>{{ value }}</td>
<td><button @click="removeCookie(key)">Remove</button></td> <td><button @click="removeCookie(key)">Remove</button></td>

View File

@ -10,7 +10,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="(user, key) in users"> <tr v-for="(user, key) in users" :key="key">
<td> <td>
<nuxt-link :to="{ path: `/users/${key}`}"> <nuxt-link :to="{ path: `/users/${key}`}">
<img :src="user.avatar" class="rounded" alt="avatar"> <img :src="user.avatar" class="rounded" alt="avatar">

View File

@ -4,7 +4,9 @@
<li class="chat page"> <li class="chat page">
<div class="chatArea"> <div class="chatArea">
<ul class="messages" ref="messages"> <ul class="messages" ref="messages">
<li class="message" v-for="message in messages"><i :title="message.date">{{ message.date.split('T')[1].slice(0, -2) }}</i>: {{ message.text }}</li> <li class="message" v-for="(message, index) in messages" :key="index">
<i :title="message.date">{{ message.date.split('T')[1].slice(0, -2) }}</i>: {{ message.text }}
</li>
</ul> </ul>
</div> </div>
<input class="inputMessage" type="text" v-model="message" @keyup.enter="sendMessage" placeholder="Type here..." /> <input class="inputMessage" type="text" v-model="message" @keyup.enter="sendMessage" placeholder="Type here..." />