【发布时间】:2017-07-26 20:18:17
【问题描述】:
我正在使用 Vue-CLI 并收到此错误。它位于<comment> 组件中。
当CommentForm 的submitComment() 方法触发并将评论对象添加到selfComments 以进行渲染时,会发生错误。可能是因为它们相互引用或其他什么,但我不确定。
我已尝试仅包含相关信息:
编辑:我认为这与此有关: https://forum.vuejs.org/t/how-to-have-indirectly-self-nested-components-in-vue-js-2/1931
CommentForm.vue
<template>
...
<ul class="self-comments">
<li is="comment" v-for="comment in selfComments" :data="comment"></li>
</ul>
...
</template>
<script>
import Comment from 'components/Comment'
export default {
name: 'comment-form',
components: {
Comment
},
props: ['topLevel', 'replyTo', 'parentId'],
data() {
return {
text: '',
postingStatus: 'Post',
error: false,
selfComments: []
}
},
methods: {
submitComment() {
...
}
}
}
</script>
<style scoped lang="scss">
...
</style>
评论.vue
<template>
...
<comment-form v-if="replyFormOpen" :top-level="false" :reply-to="data.username" :parent-id="data.id"></comment-form>
<!-- recursive children... -->
<ul>
<li is="comment" @delete="numComments -= 1" v-for="comment in data.children" :data="comment"></li>
</ul>
...
</template>
** importing CommentForm here seems to cause the issue
<script>
import CommentForm from 'components/CommentForm'
export default {
name: 'comment',
components: {
CommentForm
},
props: ['data'],
data() {
return {
deleteStatus: 'Delete',
deleted: false,
error: false,
replyFormOpen: false
}
},
methods: {
...
}
}
</script>
<style scoped lang="scss">
...
</style>
有什么想法吗?
【问题讨论】:
-
我不确定,但我认为您在加载单个文件组件(.vue 文件)时需要指定扩展名
import Comment from 'components/Comment.vue'
标签: vue.js vuejs2 vue-component