AngeloC
AngeloC

Reputation: 3523

passing an object in ejs to a vue method

in an Express app, I need to pass an object to vue method, here is the ejs template:

 <%-item.price%>

 <button v-on:click="add_to(<%=item%>)" class="float-right">Add...</button>

here is the js:

  var app = new Vue({
        el: '#app',
        data: {
            message: 'Hello Vue!'
        },
        methods: {
            add_to: function (item) {
                console.log(item)
            }
        }
    })

but it does not work, any hint? Thanks

Upvotes: 3

Views: 1315

Answers (1)

Gblend
Gblend

Reputation: 11

You need to enclose the ejs rendering the object you want to pass to the vue.js method with single quote ''

v-on:click="add_to('<%=item%>')"

Upvotes: 1

Related Questions