Mount vue3 on class attributes

Viewed 29

I want to mount vue on class opponent.

I have addToCart component that I want it to appear on class attribute "add-to-cart". I understand that vue's createApp can be only mounted on id attribute and mounting on more than one element will throw an exception.

Is there way to go about this.

1 Answers

I did it!

const els = document.querySelectorAll(".addtocart");
els.forEach(el => {
  createApp({
    el: el,
    components:{
      AddToCart
    }
  }).mount(el)
})
Related