command事件中默认传递一个参数,即你每个下拉选项el-dropdown-item中设定的command的值,怎么样传递多个参数呢?
我的项目中el-dropdown在一个遍历循环中,需要将index角标将参数传给@command="handleCommand"事件中。
解决办法:动态设置每个el-dropdown-item中command的值
<el-dropdown @command="handleCommand">
<span class="el-dropdown-link">
添加条件<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="beforeHandleCommand(index,'a')">大于*值</el-dropdown-item>
<el-dropdown-item :command="beforeHandleCommand(index,'b')">小于*值</el-dropdown-item>
<el-dropdown-item :command="beforeHandleCommand(index,'c')">区间</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
js部分:
//返回新的command对象
beforeHandleCommand(index,command){ //index我这里是遍历的角标,即你需要传递的额外参数
return {
'index': index,
'command':command
}
},
handleCommand(command) {
switch (command.command) { //角标index获取为command.index
case "a":
break;
case "b":
break;
case "c":
break;
}
},