P
P
Peter2020-07-30 19:10:23
JavaScript
Peter, 2020-07-30 19:10:23

How to use vue on a collection of elements?

Good afternoon. There is a one-page online store, the page of which is built at the expense of Razor. A list of products is displayed from the database. At the moment, vanilla JS describes the logic of adding products to the cart, saving it in LocalStorage. The cart itself is implemented using a modal window.
The cart itself is rendered in the modal via innerHTML or via appendChild.
After looking at the information that vue can be connected simply with a file to the project, I decided to implement all the logic of drawing a basket and adding products on vue. But, in all examples, vue clings to the block id.
I have the opposite. There is a set of product cards. When clicked, the product is added to the cart. How do I hook up a click listener via vue to a group of elements.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2020-07-31
@Morpheus_God

Vue doesn't quite work that way.
It starts from javascript data and html is built on it.
Those. this div to which vue clings serves as a template, not a data source. Its content will be replaced by Vue.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question