0

Parent component: ShowComment

Child component: EditComment

I'm trying to pass the value of this.CommentRecID to the child component.

I wrote this in the template of ShowComment:

<EditComment CommentRecID="this.CommentRecID" v-if="showEdit"></EditComment>

and

this.showEdit = true;

but the value of this.CommentRecID is shown as undefined in the child component:

enter image description here

I thought that writing props: ["CommentRecID"], in the child component would have already been enough to pass the data, but it wasn't (because it's related to jQuery I think).

What is wrong with the way I try to pass the values?

Here's the parent component.

Here's the child component.

2 Answers 2

1

You shouldn't need to use this in VueJS directives. Also, instead of using a static attribute, you need to use v-bind:

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

Also, there's an issue with the casing: for VueJS, in template props should be kebab-cased, while in the component JS logic you should use camelCase props. Remember to update your child component's prop declaration so that it can read the new prop correctly:

 props: ["commentRecId"]
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your reply. I made the changes you suggested, but somehow I still get an undefined value for CommentRecID. Do you know what the cause might be?
Looks like your parent element is also receiving it as a prop. Go up the dependency chain until you find the source of CommentRecId, and rename all instances of it in JS to camelCase, and all template references to kebab-case. In general though, you should never use PascalCase for your variables unless it's a class.
@PoliticsStudent No problem, happy to help!
1

You need to use VueJS binding

<EditComment :comment-rec-id="CommentRecID" v-if="showEdit"></EditComment>
props: ['commentRecId']

Comments

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.