具体问题的描述:

<div v-for="article in articles" style="margin:13px">
    <div class="article-image">
        <a>
        <img :src="article.image_path"/>
        </a>
    </div>
    <div class="article-title">
        <h4>{{article.title}}</h4>
    </div>
    <div class="article-content">
        <p v-html="article.content"></p>
    </div>
</div>
Vue.component('article_item', {
    template: "#article-template",
    replace: true,
    props: {
        articles: Array
    }
});

前端报错:

Cannot use v-for on stateful component root element because it renders multiple elements.

原因:

v-for不能用于根元素(root element)。因为v-for是个循环,它返回更多的元素。导致无法渲染

解决办法:

添加根节点

<div id="test">
    <div  v-for="objects in object"> {{ object.value }}</div>
</div>
Logo

前往低代码交流专区

更多推荐