vue.js and rails erb: How to place v-model tag ins

2019-06-04 14:55发布

问题:

I am currently trying to include a vue.js v-model into my erb form input tag and I cannot find the right syntax.

Here is how my code currently looks:

<div class="field">
   <%= f.text_field :first_name, v-model="firstname" %>
</div>

I would very much appreciate any idea here. Thanks!

回答1:

try this:

<%= f.text_field :first_name, "v-model": "first_name" %>

Works for me



回答2:

FYI, for anyone else looking use Vue.js in ERB tags, @carlos-orellana's answer also works for:

"v-on:click": "clickEvent"

My guess is that it would work for most Vue bindings. Kudos to Carlos.