Vuejs2 渲染时出错:";TypeError:无法读取属性';字段名';“未定义”的定义;

Vuejs2 渲染时出错:";TypeError:无法读取属性';字段名';“未定义”的定义;,vuejs2,laravel-5.4,vue-component,vuex,laravel-mix,Vuejs2,Laravel 5.4,Vue Component,Vuex,Laravel Mix,我正在呈现一个自定义组件列表(这只是一个示例),如下所示: <template> <ul> <li v-for="(item, index) in componentList" :field-name="MyFieldName" > <custom_component :index="index"

我正在呈现一个自定义组件列表(这只是一个示例),如下所示:

<template>
    <ul>
        <li
                v-for="(item, index) in componentList"

                :field-name="MyFieldName"
         >
               <custom_component :index="index" 
                   :some-prop="item.someProps" />
        ></li>
    </ul> 
</template>

<script> 


 export default { 
   name: 'myListComp';

   props: {

     },
     ... other props
  },

  data () {
   return {
        /// ... some other variable/properties for this instance
        myFieldName: '',
       componentList: []
    }
   },

  created () {
        // ...
       Load data from props
       this.myFieldName = this.fieldName;
       // Initialize Component List with the data
       this.componentList = this.initializeComponentList();
         // ...
    },

    methods:{
      initializeComponentList() { 
        // Get the list from AJAX
        return [{}, {}, ....];
      }
    }

} 
</script>

  • >
导出默认值{ 名称:“myListComp”; 道具:{ }, …其他道具 }, 数据(){ 返回{ ///…此实例的其他一些变量/属性 myFieldName:“”, 组件列表:[] } }, 创建(){ // ... 从道具加载数据 this.myFieldName=this.fieldName; //使用数据初始化组件列表 this.componentList=this.initializeComponentList(); // ... }, 方法:{ initializeComponentList(){ //从AJAX获取列表 返回[{},{},…]; } } }
在呈现组件列表时,我遇到一些奇怪的错误,如下所示

顺便说一句。。。我正在使用最新的laravel mix ^2.1.11编译vue组件。我正在使用Vue^2.5.16和vuex^3.0.1。

我发现问题在于,当我们使用v-for循环渲染组件时,vueJS的独特关键要求。我只是添加了一个新函数来创建唯一索引,它解决了我的问题。请演示如何使用组件
我通过在呈现列表中传递唯一键来解决它。