ElementUI中的el-dropdown傳入多參數(shù)的實(shí)現(xiàn)方法
最近工作中因?yàn)闃I(yè)務(wù)中按鈕的增多,導(dǎo)致頁(yè)面排版按鈕過(guò)多,頁(yè)面不夠美觀,用戶體驗(yàn)不佳,于是想到利用el-dropdown做一個(gè)下拉按鈕(把多個(gè)按鈕整合到了一起,下拉實(shí)現(xiàn))
但是ElementUi官方文檔中的handleCommand方法只允許接入一個(gè)參數(shù),這個(gè)參數(shù)用于觸發(fā)你選擇的是哪一個(gè)選項(xiàng)。而我們實(shí)際中還需要傳入一個(gè)當(dāng)前行數(shù)(如果和我一樣,也是用table顯示數(shù)據(jù)的話)的對(duì)象進(jìn)去,后面要使用這個(gè)對(duì)象的某些字段傳給后臺(tái)進(jìn)行一些增刪改查的操作。
ElementUi官方文檔中el-dropdown的樣例如下:
el-dropdown 官方文檔
<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="a">黃金糕</el-dropdown-item> <el-dropdown-item command="b">獅子頭</el-dropdown-item> <el-dropdown-item command="c">螺螄粉</el-dropdown-item> <el-dropdown-item command="d" disabled>雙皮奶</el-dropdown-item> <el-dropdown-item command="e" divided>蚵仔煎</el-dropdown-item> </el-dropdown-menu> </el-dropdown> <style> .el-dropdown-link { cursor: pointer; color: #409EFF; } .el-icon-arrow-down { font-size: 12px; } </style> <script> export default { methods: { handleCommand(command) { this.$message('click on item ' + command); } } } </script>
我們必須在執(zhí)行handleCommand方法之前,對(duì)這個(gè)command參數(shù)進(jìn)行重新封裝成一個(gè)對(duì)象,使其內(nèi)部包含我們想要的數(shù)據(jù)方便后面調(diào)用。
代碼如下:
<el-table-column label="操作1"> <template slot-scope="scope"> <el-dropdown split-button type="primary" @command="handleCommand"> 其他操作 <el-dropdown-menu slot="dropdown" > <el-dropdown-item :command="beforeHandleCommand(scope.$index, scope.row,'a')">廢棄</el-dropdown-item> <el-dropdown-item :command="beforeHandleCommand(scope.$index, scope.row,'b')">上傳原件</el-dropdown-item> <el-dropdown-item :command="beforeHandleCommand(scope.$index, scope.row,'c')">原件整理</el-dropdown-item> <el-dropdown-item disabled :command="beforeHandleCommand(scope.$index, scope.row,'d')">凍結(jié)</el-dropdown-item> <el-dropdown-item disabled :command="beforeHandleCommand(scope.$index, scope.row,'e')">解凍</el-dropdown-item> </el-dropdown-menu> </el-dropdown> </template> </el-table-column>
因?yàn)槲覀兪菍懺诒砀窭锏?,所以需要一個(gè)插槽,具體的根據(jù)實(shí)際情況進(jìn)行修改。給標(biāo)簽的command屬性綁定一個(gè)方法,這個(gè)方法就可以傳入我們想要的參數(shù),然后利用這個(gè)方法封裝成一個(gè)對(duì)象,再將這個(gè)對(duì)象傳入handleCommand方法。
<script> export default { methods: { handleAbandon(index, row) { //todo }, handleUpload (index, row) { //todo }, handleSettle(index, row){ //todo }, beforeHandleCommand(index, row,command){ return { 'index': index, 'row': row, 'command':command } }, handleCommand(command) { switch (command.command) { case "a"://廢棄 this.handleAbandon(command.index,command.row); break; case "b"://上傳原件 this.handleUpload (command.index,command.row); break; case "c"://原件整理 this.handleSettle(command.index,command.row); break; } } }, } </script>
到此這篇關(guān)于ElementUI中的el-dropdown傳入多參數(shù)的實(shí)現(xiàn)方法的文章就介紹到這了,更多相關(guān)ElementUI中el-dropdown傳入多參數(shù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用Vite+Vue3+Vant全家桶快速構(gòu)建項(xiàng)目步驟詳解
這篇文章主要為大家介紹了使用Vite+Vue3+Vant全家桶快速構(gòu)建項(xiàng)目步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06vue?使用el-table循環(huán)輪播數(shù)據(jù)列表的實(shí)現(xiàn)
這篇文章主要介紹了vue?使用el-table循環(huán)輪播數(shù)據(jù)列表的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04vue使用echarts實(shí)現(xiàn)地圖的方法詳解
這篇文章主要為大家詳細(xì)介紹了vue使用echarts實(shí)現(xiàn)地圖的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2022-03-03Vue2.0如何發(fā)布項(xiàng)目實(shí)戰(zhàn)
本篇文章主要介紹了Vue2.0如何發(fā)布項(xiàng)目實(shí)戰(zhàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07項(xiàng)目遷移vite引入圖片資源報(bào)require?is?not?defined問(wèn)題的解決辦法
這篇文章主要給大家介紹了關(guān)于項(xiàng)目遷移vite引入圖片資源報(bào)require?is?not?defined問(wèn)題的解決辦法,文中通過(guò)代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用vite具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-01-01