Vue의 v-for에서 bind를 하면 Lint한테 혼나는데 뭐가 안 되지...(Elements in iteration expect to have 'v-bind:key' directives) ( #Vue )
4537 단어 Vue.js
data
데이터가 이럴 때. data () {
return {
posts: [
{ id: 1, title: 'My journey with Vue' },
{ id: 2, title: 'Blogging with Vue' },
{ id: 3, title: 'Why Vue is so fun' }
]
}
NG <li v-for="post in posts">
{{ post.title }}
</li>
OK <li v-for="post in posts" :key="post.id">
{{ post.title }}
</li>
OK ...?
bind의 값은 특별히 v-for에서 표시하는 것이 아니다
존재하지 않는 키를 지정해도 동작합니다. lint에서 욕을 먹지 않습니다.<li v-for="post in posts" :key="post.xxx">
{{ post.title }}
</li>
왠지 모르다
단지 표시일 뿐이라면 우선 bind 지정이 없어도 문제없지만, 삭제할 때 유일하게 요소를 확정하기 위한 것인가
[철저 해설] 이거 보면 vue.js의 v-for의 키 동작
Code <template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<ul>
<li v-for="post in posts">
{{ post.id }} {{ post.title }}
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'App',
data () {
return {
posts: [
{ id: 1, title: 'My journey with Vue' },
{ id: 2, title: 'Blogging with Vue' },
{ id: 3, title: 'Why Vue is so fun' }
]
}
}
}
</script>
Original by Github issue
Reference
이 문제에 관하여(Vue의 v-for에서 bind를 하면 Lint한테 혼나는데 뭐가 안 되지...(Elements in iteration expect to have 'v-bind:key' directives) ( #Vue )), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/YumaInaura/items/56875026b8b00970080b
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
data () {
return {
posts: [
{ id: 1, title: 'My journey with Vue' },
{ id: 2, title: 'Blogging with Vue' },
{ id: 3, title: 'Why Vue is so fun' }
]
}
<li v-for="post in posts">
{{ post.title }}
</li>
OK <li v-for="post in posts" :key="post.id">
{{ post.title }}
</li>
OK ...?
bind의 값은 특별히 v-for에서 표시하는 것이 아니다
존재하지 않는 키를 지정해도 동작합니다. lint에서 욕을 먹지 않습니다.<li v-for="post in posts" :key="post.xxx">
{{ post.title }}
</li>
왠지 모르다
단지 표시일 뿐이라면 우선 bind 지정이 없어도 문제없지만, 삭제할 때 유일하게 요소를 확정하기 위한 것인가
[철저 해설] 이거 보면 vue.js의 v-for의 키 동작
Code <template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<ul>
<li v-for="post in posts">
{{ post.id }} {{ post.title }}
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'App',
data () {
return {
posts: [
{ id: 1, title: 'My journey with Vue' },
{ id: 2, title: 'Blogging with Vue' },
{ id: 3, title: 'Why Vue is so fun' }
]
}
}
}
</script>
Original by Github issue
Reference
이 문제에 관하여(Vue의 v-for에서 bind를 하면 Lint한테 혼나는데 뭐가 안 되지...(Elements in iteration expect to have 'v-bind:key' directives) ( #Vue )), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/YumaInaura/items/56875026b8b00970080b
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
<li v-for="post in posts" :key="post.id">
{{ post.title }}
</li>
bind의 값은 특별히 v-for에서 표시하는 것이 아니다
존재하지 않는 키를 지정해도 동작합니다. lint에서 욕을 먹지 않습니다.
<li v-for="post in posts" :key="post.xxx">
{{ post.title }}
</li>
왠지 모르다
단지 표시일 뿐이라면 우선 bind 지정이 없어도 문제없지만, 삭제할 때 유일하게 요소를 확정하기 위한 것인가
[철저 해설] 이거 보면 vue.js의 v-for의 키 동작
Code <template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<ul>
<li v-for="post in posts">
{{ post.id }} {{ post.title }}
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'App',
data () {
return {
posts: [
{ id: 1, title: 'My journey with Vue' },
{ id: 2, title: 'Blogging with Vue' },
{ id: 3, title: 'Why Vue is so fun' }
]
}
}
}
</script>
Original by Github issue
Reference
이 문제에 관하여(Vue의 v-for에서 bind를 하면 Lint한테 혼나는데 뭐가 안 되지...(Elements in iteration expect to have 'v-bind:key' directives) ( #Vue )), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/YumaInaura/items/56875026b8b00970080b
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<ul>
<li v-for="post in posts">
{{ post.id }} {{ post.title }}
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'App',
data () {
return {
posts: [
{ id: 1, title: 'My journey with Vue' },
{ id: 2, title: 'Blogging with Vue' },
{ id: 3, title: 'Why Vue is so fun' }
]
}
}
}
</script>
Original by Github issue
Reference
이 문제에 관하여(Vue의 v-for에서 bind를 하면 Lint한테 혼나는데 뭐가 안 되지...(Elements in iteration expect to have 'v-bind:key' directives) ( #Vue )), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/YumaInaura/items/56875026b8b00970080b
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(Vue의 v-for에서 bind를 하면 Lint한테 혼나는데 뭐가 안 되지...(Elements in iteration expect to have 'v-bind:key' directives) ( #Vue )), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/YumaInaura/items/56875026b8b00970080b텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)