【发布时间】:2020-07-23 16:22:50
【问题描述】:
我在组件 A 中有一个变量 commentRecId,我想传递它以在组件 B 中使用它。
我将它包含在组件 A 的模板中:
<EditComment v-bind:comment-rec-id="commentRecId" v-if="showEdit"></EditComment>
我在组件A的方法中将showEdit设置为true:
methods: {
loadComments: function() {
this.showEdit = true;
console.log("this.ShowEdit in ShowComment: " + this.showEdit);
console.log("commentRecID in ShowComment: " + this.commentRecId);
到目前为止,这一切都很好,commentRecID 确实有价值。
问题是变量 commentRecId 在其他组件 B 中显示为未定义,经过数小时的反复试验,我仍然不明白为什么。
在组件 B 中,我在 props 中有这个:
export default {
props: ["commentRecId"],
并用它来引用变量:
var statID = this.commentRecId;
console.log("Edit Comment this.commentRecId: " + statID);
谁能告诉我我做错了什么?
【问题讨论】:
标签: javascript jquery vue.js vue-component vue-props