0

I have a variable commentRecId in component A, that I want to pass to use it in component B.

I included this in the template of component A:

<EditComment v-bind:comment-rec-id="commentRecId" v-if="showEdit"></EditComment>

I set showEdit to true in the methods of component A:

methods: {
  loadComments: function() {
    this.showEdit = true;
    console.log("this.ShowEdit in ShowComment: " + this.showEdit);
    console.log("commentRecID in ShowComment: " + this.commentRecId);

Up until now this works perfectly fine and commentRecID does have a value.

The problem is that the variable commentRecId is shown as undefined in the other component B and after hours of trial and error I still don't understand why.

In component B, I have this in the props:

export default {
    props: ["commentRecId"],

and used this to reference the variable:

var statID = this.commentRecId;
console.log("Edit Comment this.commentRecId: " + statID);

enter image description here

Can someone tell me what I'm doing wrong?

(Component A) (Component B)

0

1 Answer 1

1

Try to set statID as a computed property use it in the mounted hook :

computed :{
  statID (){
   return this.commentRecId;
  }

}



and reference it in mounted hook by prefixing it with this like console.log("Edit Comment this.commentRecId: " + this.statID);

Sign up to request clarification or add additional context in comments.

7 Comments

How do I have to reference statID in mounted?
You could reference it like console.log("Edit Comment this.commentRecId: " + this.statID);
Hmm, I get a ReferenceError: statID is not defined at a.mounted
did you add this before it like this.statID
I experimented a bit, now it just says that it's undefined. This is what it looks like after your suggestion: pastebin.com/PJrZJ4N6
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.