思路:methods 中写个通用事件,每个按钮都调用这个通用事件 ,在这个通用事件 中再去调用对应的事件。
代码如下
<template>
<!-- 平行世界 -->
<div id="control">
<template v-for="(item,i) in functionList">
<div class="item" :key="i" @click="control(item.method)">{{item.label}}</div>
</template>
</div>
</template>
<script>
export default {
name: "",
data() {
return {
functionList:[
{label: "坐标转换", method: "transform"}
]
};
},
mounted(){
this.init();
},
methods: {
init(){},
control(type){
this[type]();
},
transform(){
console.log('transform');
}
},
};