当先锋百科网

首页 1 2 3 4 5 6 7

require v-bind:key with v-for directives (vue/require-v-for-key)

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

解决方案:

 

<template>
  <div id = 'app'>
   <h1>{{ msg }}</h1>
   <h2>{{ name }}</h2>
   <ul>
        <li v-for="item in movies">{{ item }}</li>
   </ul>
  </div>
</template>

问题:<li v-for="item in movies">{{ movies[i] }}</li> 报错:Elements in iteration expect to have 'v-bind:key' directives.eslintvue/require-v-for-key

改成:   <li v-for="item in movies" :key="item">{{ movies[i] }}</li>

<template>
  <div id = 'app'>
   <h1>{{ msg }}</h1>
   <h2>{{ name }}</h2>
   <ul>
        <li v-for="item in movies" :key="item">{{ item }}</li>
   </ul>
  </div>
</template>