Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在vue.js中显示嵌套对象_Javascript_Object_Nested_Vue.js_Vue Resource - Fatal编程技术网

Javascript 如何在vue.js中显示嵌套对象

Javascript 如何在vue.js中显示嵌套对象,javascript,object,nested,vue.js,vue-resource,Javascript,Object,Nested,Vue.js,Vue Resource,我返回的数据是一个包含嵌套对象的对象数组。我无法在模板中的v-for循环中显示“事件”,因为我似乎无法访问返回数据的该部分 返回的数据如下(从Vue DevTools): 使用Vue资源(通过CDN)如何仅显示模板中的事件 模板: <template id="events-template"> <div v-for="events in list"> @{{events.title}} </div> </template>

我返回的数据是一个包含嵌套对象的对象数组。我无法在模板中的v-for循环中显示“事件”,因为我似乎无法访问返回数据的该部分

返回的数据如下(从Vue DevTools):

使用Vue资源(通过CDN)如何仅显示模板中的事件

模板:

<template id="events-template">
  <div v-for="events in list">
    @{{events.title}}
  </div>    
</template>

好的,看起来您试图访问循环中的假属性

list
变量不包含列表/数组(对象)。要迭代的数组是
列表
对象的events属性。所以
list.events

此外,您希望访问循环中“当前”项(事件)的属性(标题)。然后,您不必访问孔阵列,而是访问当前元素<代码>事件.标题

替换模板块:

<template id="events-template">
    <div v-for="event in list.events">
        @{{event.title}}
    </div>    
</template>

@{{event.title}

能否将
列表
变量的json添加到您的问题中?@Fiete我不完全确定您的意思;但是,我已经重写了第一个代码块,以匹配Vue DevTools中显示的确切响应
Vue.component('events', {
template: '#events-template',

data: function() {
    return {
        list: []
    }
},

created: function() {
    this.fetchEventsList();
},

methods: {
    fetchEventsList: function() {
        this.$http.get('events', function(events) {
            this.list = events;
        }).bind(this);
    }
}

});
<template id="events-template">
    <div v-for="event in list.events">
        @{{event.title}}
    </div>    
</template>