【发布时间】:2019-12-12 22:21:35
【问题描述】:
我有以下组件
<template>
<li v-for="(item, i) in this.menu" :key="i" @click="item.action()"> //trying to call the method in the component
{{menu.title}}
<li>
</template>
<script>
export default {
data: () => ({
menu: [
{title: 'Start Preparing', action: this.startPrepare}, //how do I reference the method here?
{title: 'Cancel Order'},
],
}),
methods: {
startPrepare: function (orderId) {
console.log("start")
}
}
}
</script>
正如您在评论部分看到的,我在数据部分有一个menu,它有一个title 和action 属性。因此,在模板中,当有人单击该特定项目时,我想调用我们指定的任何函数。
那么我如何在该组件的数据部分中引用同一组件中的方法?截至目前,我开始准备是undefined 错误。
如果需要进一步说明,请告诉我
【问题讨论】:
标签: javascript vue.js vuejs2 vuetify.js