v-for报"Elements in iteration expect to have 'v-bind:key' directives"错误的解决方案

一、 问题日志

  ✘  https://google.com/#q=vue%2Frequire-v-for-key  Elements in iteration expect to have 'v-bind:key' directives  
  src/components/home.vue:36:13
              <li v-for="year in objective">
               ^


二、 问题原因

在vue新版本中,v-for迭代语法有变动,需要加入key值。


三、 解决方案

v-for="year in objective"

后面加上key值定义,注意有个空格

v-for="year in objective" :key="year.num"

四、 参考文献

  • require v-bind:key with v-for directives (vue/require-v-for-key)
  • ‘v-for’ directives require ‘v-bind:key’ directives.

你可能感兴趣的:(Vue.js)