遍历key值,传对应的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>
网友评论