【发布时间】:2018-10-19 12:11:18
【问题描述】:
我正在尝试制作一个简单的帖子列表组件,我在其中使用 v-for 指令,但我看到以下错误:
"eslint-eslint: the template root disallows v-for directives"
我应该如何循环和呈现每个帖子?
我将 allBehaviourPosts 作为道具从 Laravel 后端传递给组件,如下所示:
<related-post-list :relatedBehaviourPost= {{ $relatedBehaviourPosts }}></>
我的组件:
<template>
<div class="sidebar_related_content_container" v-for="behaviour in relatedBehaviourPosts " :key="behaviour.id" style="">
<a class="sidebar_related_content_image" href="/conducta-canina/{{ relatedBehaviour.slug }}" style="background-image:url('{{ behaviour.image }}');">
<div class="black_gradient" style=""></div>
</a>
<div class="sidebar_related_content_text_container" style="">
<span class="sidebar_related_content_text_title" style="">{{ behaviour.postcategory.name }}</span>
<span class="sidebar_related_content_text_description" style="">{{ behaviour.title }}</span>
</div>
</div>
</template>
<!--SCRIPTS-->
<script>
export default {
props: ['relatedBehaviourPosts'],
data: function () {
return {
//data
}
},
mounted() {
console.log('Footer mounted.')
}
}
</script>
<!--STYLES-->
<style scoped>
</style>
【问题讨论】:
标签: javascript loops templates vue.js vuejs2