vuejs / Discussion

Vue.js discussion
167 stars 17 forks source link

[HELP] Pass variable to Vue #386

Closed oleynikd closed 9 years ago

oleynikd commented 9 years ago

First of all - thank you guys for such a great work!!!

I'm building an web site..) Let's say it's a list of books. I bundle my JS with browserify. I have my Vue code that will perform search within the list of books. JS code is static so it is bounded and versioned in big js file. But my array of books is dynamic and loaded from server with html.

The question is: how do I pass my array of books from loaded html to a bundled Vue script? The first thought is to use dependency injection and expose Vue script to window... But is it the only one solution?

Thanks!

simplesmiler commented 9 years ago

What do you mean by "loaded from server with html"? Is it ajax with html-fragment response? Or array is rendered as script by the server? Or rendered as markup (e.g. <ul><li>...</li></ul>)?

My approach for this is:

oleynikd commented 9 years ago

Hi Denis, Thanks for reply.

It is rendered in <script> tag inside html. I ended up exposing component to global and passing array to initializer...