2

I am using VueJS with a PHP application. I have multiple posts with comments for each of them. Each of them has a class answer_comment. I am trying to make VueJS work for all of them (it currently only works with one).

new Vue({ el: '.answer_comment', /* other code */ })

This only affects the first one. How can I make it work for all of them? How can I select all elements with the class of answer_comment instead of only getting the first one?

1 Answer 1

0

UPDATE: Since this answer was given, Vue now disallows mounting a VM on the body tag. So, use some element beneath it.

Using the new Vue approach is really just setting up a single View Model with its own hierarchy. It will end up just matching the first DOM element that matches your CSS selector.

In this case, I recommend moving your new Vue up to the body tag and declare an "answer_comment" component for it that Vue will then apply throughout the body when it "compiles" it.

See the component documentation for more information:

http://vuejs.org/guide/components.html

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

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.