Add... 这是js: var app = ne-6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 06:33:00 25 4
gpt4 key购买 nike

在 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)
}
}
})

但是它不起作用,有什么提示吗?谢谢

最佳答案

您需要用单引号将渲染您要传递给 vue.js 方法的对象的 ejs 括起来 ''

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

关于vue.js - 将 ejs 中的对象传递给 vue 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50978237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com