将ejs中的对象传递给vue方法

时间:2018-06-21 22:24:58

标签: vue.js ejs

在Express应用中,我需要将对象传递给vue方法,这是ejs模板:

 <%-item.price%>

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

这是js:

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

但是它不起作用,有任何提示吗?谢谢

1 个答案:

答案 0 :(得分:1)

你需要用单引号 '' 将呈现你想要传递给 vue.js 方法的对象的 ejs 括起来

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