
<template>
<div class="app-container">
<el-button v-for="(item, index) in BUTTON_CONFIG" :key="index" @click="bundleClick(item)">重置</el-button>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
interface ButtonType { text: string; event: string; params?: any; }
type ButtonKey = 'add' | 'update' | 'delete';
const BUTTON_CONFIG = ref<Record<ButtonKey, ButtonType>>({
add: {
text: '修改',
event: 'click1',
},
update: {
text: '积分修改',
event: 'click2',
params: '1',
},
delete: {
text: '成长值修改',
event: 'click3',
params: '2',
},
// ...很多按钮配置
});
const bundleClick = (btnItem: ButtonType) => {
// 如何像vue2一样通过this[btnItem.event](btnItem.params) 一样调用,以及如何增加ts类型;
}
const click1 = () => { console.log('click1'); }
const click2 = () => { console.log('click2'); }
const click3 = () => { console.log('click3'); }
</script>
这样?