问题
在做一个vue项目时,Element Plus中Tabs组件自带的点击函数参数只有2个,现在想要给Element Plus中Tabs组件中的点击函数多传一个参数。
<el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
<el-tab-pane label="User" name="first">User</el-tab-pane>
<el-tab-pane label="Config" name="second">Config</el-tab-pane>
<el-tab-pane label="Role" name="third">Role</el-tab-pane>
<el-tab-pane label="Task" name="fourth">Task</el-tab-pane>
</el-tabs>
const handleClick = (tab: TabsPaneContext, event: Event) => {
console.log(tab, event)
}
解决思路
闭包原理解决
<el-tabs v-model="activeName" class="demo-tabs" @tab-click="(tab, event) => { handleClick(tab, event, 'bb') }">
<el-tab-pane v-for="(item,index) in array" :label="item.label" :name="item.name" >{{item.label}}</el-tab-pane>
</el-tabs>
const handleClick = (tab,event,val) => {
console.log(val) // bb
}