核心代码
buttonClick(methodName) { this[methodName]() },
完整范例代码
<template> <div style="padding: 20px"> <button v-for="(item,index) in buttonList" :key="index" @click="buttonClick(item.methodName)"> {{item.label}} </button> </div> </template> <script> export default { data() { return { buttonList: [ { label: '新增', methodName: 'add' }, { label: '修改', methodName: 'edit' }, ] } }, methods: { buttonClick(methodName) { this[methodName]() }, add() { alert('新增') }, edit() { alert("修改") } }, } </script> <style scoped> </style>