我创建了一个Vue组件,它有一个最初的AJAX调用,获取一个对象数组,我将通过循环遍历这些对象。是否有一种方法将这些对象定义/转换为另一个Vue组件?这是我目前的进展:
var myComponent = Vue.extend({
template: '#my-component',
created: function() {
this.$http
.get('/get_objects')
.then(function(data_array) {
for (var i = 0; i < data_array.data.length; i++) {
var item = data_array.data[i];
// <<-- How do i tell vue to cast another component type here??
}
}
);
}
});
Vue.component('my-component', myComponent);
new Vue({
el: 'body',
});
<child-component v-for="item in list"></child-component>
。 - Joseph SilberVue
的做法是,先定义好组件,然后通过填充数据并使用v-if
/v-show
显示单个组件,或者使用v-for
显示多个组件。 - Yerko Palmaitem
变量?它似乎在子模板中不可用。 - chrisg86<tr is="child-component" v-for="item in list" :item="item"></tr>
。 - Jeff