遍歷key值壶辜,傳對應(yīng)的key
<template>
<div>
<template
v-for="(item, key) in list"
:key="key"
>
<el-button
:class="'handle-' + key"
@click="handle(key)"
>{{item}}</el-button>
</template>
</div>
</template>
<script>
export default {
data() {
return {
list: {
edit: '編輯',
delete: '刪除',
},
};
},
methods: {
handle(type) {
let fn = `this.handle${type}()`;
eval(fn);
},
handleedit() {
console.log('edit');
},
handledelete() {
console.log('delete');
},
},
};
</script>