Skip to content

Vue, Twig (PHP), and set initial value from server #9692

Closed Answered by domialbrecht
lucpotage asked this question in Help/Questions
Discussion options

You must be logged in to vote

I am currently doing something similar. My current approach is as follows:

// I create my store globally, and pass the same instance to my vueApps.
// With this all instances share the same store state
const Pinia = createPinia() 

const appElements = document.querySelectorAll('[data-vueapp]') //Change this to match your elements in Twig.
appElements.forEach((element) => {
  // Here I currently just pass the id set on the wrapper element.
  // You could add data attributes or if you want pass globally available variables set by your script
  const app = createApp(App, { app: element.id }
  app.use(Pinia)
  app.mount(element)
})

I am not sure if this covers your usecase, but it has worked …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@domialbrecht
Comment options

Answer selected by lucpotage
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants