分享一个在刚接触前端开发的开发者常遇到的一个经典错误,那就是在Vue项目运行中遇到Emitted value instead of an instance of Error的问题,附带解决该问题的方法以及原理。
重现报错提示:
(Emitted value instead of an instance of Error) <van-cell v-for=" item in this.todoList">: component lists rendered with v-for should have explicit keys. See https://vuejs.org/guide/list.html#key for more info.
由于上述警告造成Vue项目不能启动,警告的大概意思就是在组件里面使用v-for 但是没有设置key,会造成非唯一性问题。
针对上述问题的解决方法:
在警告的组件里面v-for后面加一个属性key,为元素绑定了一个key,v-for="(item, index) in this.to