0

I have a Vue.component which creates a row in a table:

 Vue.component('comment-row', {
                props: ['comment'],
                template: '<tr>' +
                    '<th>{{comment.authorName}}</th>' +   // works fine
                    '<th>{{comment.value}}</th>' +  // also works fine
                    '<th><form action="/remove_comment/{{comment.id}}">' +  // problem here
                    '<button type="submit">X</button></form></th>' +
                    '</tr>'
            });

The row looks like:

Author | Some message | Button 'X' to delete this row with unique action

And there is a problem here: Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead.

Ok, we do what we are asked:

<form v-bind:action="/remove_comment/comment.id">

But here another problem arises: Invalid regular expression flags in

Instead of a number I get string comment.id

The question is how to use ['comment'] prop correctly in a html tag action = "" in Vue.js?

2 Answers 2

1

You can use v-bind like this:

<form v-bind:action="'/remove_comment/' + comment.id"></form>

Or use a computed property for cleaner code v-bind:action="mycomputedProperty"

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

Comments

1

Shorthand Version of Iwan's Answer.

Reference from vue.js docs

<form :action="'/remove_comment/' + comment.id"></form>

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.