【发布时间】:2021-01-10 03:20:44
【问题描述】:
我想将组件方法分配给数据变量,请参见下面的示例代码。可惜它不起作用,正确的方法是什么?
<li v-for="item in items" @click="item.action">
{{ item.title }}
</li>
export default {
data: () => ({
items: [
{ title: "One", action: this.funcOne },
{ title: "Two", action: this.funcTwo },
]
}),
methods: {
funcOne() {
alert("Hi")
},
funcTwo() {
alert("Hello")
}
}
}
【问题讨论】:
标签: javascript vue.js vuejs2 vue-component