I am trying to learn how to build an app with Rails 5.1 with Vuejs, as generated via the Webpacker gem.
$ rails new myvueapp --webpack=vue
How do I pass instance variable data back an forth between the Vue components, to get my data in/out of the database?
Let's say for example that I have a User model with Username and Email fields. Is there a simple example of how to pass instance variable, @user, data from the controller to a component?
I believe there are two ways to do this:
(1) In the controller, has the render :json => @user and then use something like the fetch API or Axios to retrieve the data in the .vue component.
-or-
(2) Use the something like the example <%= javascript_pack_tag 'hello_vue' %> together with a <%= content_tag ... %> in a view.
When I do this <%= javascript_pack_tag 'hello_vue' %> example, I can see the "Hello Vue!" from the data in the component "message" variable, but am having trouble finding an example of instance variable data, eg: @user data, being passed in and out of Rails.
Any examples of how to pass @user data would be much appreciated.
Thank you.