如何在遍历情况下给button赋不同的click事件
2021-08-06 本文已影响0人
成神之路_be73
遍历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>