fro*_*sty 3 vue.js vue-component vuejs2
我正在使用Vue-CLI并收到此错误。在<comment>组件中找到它。
当CommentForm的submitComment()方法触发并添加selfComments要呈现的注释对象时,将发生错误。可能是因为它们相互引用或引用某些东西,但是我不确定。
我尝试仅包含相关信息:
编辑:我认为这与此有关: https : //forum.vuejs.org/t/how-to-have-inve-indirect-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>
Run Code Online (Sandbox Code Playgroud)
评论
<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>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我认为您遇到了这个问题:组件之间的循环引用。
在您的CommentForm成分,尝试注册Comment的过程中组件beforeCreate()的事件。这将有助于Vue的身影出正确的顺序来解析的组件。
<script>
export default {
name: 'comment-form',
props: ['topLevel', 'replyTo', 'parentId'],
data() {
return {
text: '',
postingStatus: 'Post',
error: false,
selfComments: []
}
},
methods: {
submitComment() {
...
}
},
beforeCreate() {
// register the Comment component here!!!!
this.$options.components.Comment = require('components/Comment.vue');
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1174 次 |
| 最近记录: |