ElementUI中的el-dropdown傳入多參數(shù)的實現(xiàn)方法
最近工作中因為業(yè)務(wù)中按鈕的增多,導致頁面排版按鈕過多,頁面不夠美觀,用戶體驗不佳,于是想到利用el-dropdown做一個下拉按鈕(把多個按鈕整合到了一起,下拉實現(xiàn))
但是ElementUi官方文檔中的handleCommand方法只允許接入一個參數(shù),這個參數(shù)用于觸發(fā)你選擇的是哪一個選項。而我們實際中還需要傳入一個當前行數(shù)(如果和我一樣,也是用table顯示數(shù)據(jù)的話)的對象進去,后面要使用這個對象的某些字段傳給后臺進行一些增刪改查的操作。
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方法之前,對這個command參數(shù)進行重新封裝成一個對象,使其內(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>
因為我們是寫在表格里的,所以需要一個插槽,具體的根據(jù)實際情況進行修改。給標簽的command屬性綁定一個方法,這個方法就可以傳入我們想要的參數(shù),然后利用這個方法封裝成一個對象,再將這個對象傳入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ù)的實現(xiàn)方法的文章就介紹到這了,更多相關(guān)ElementUI中el-dropdown傳入多參數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用Vite+Vue3+Vant全家桶快速構(gòu)建項目步驟詳解
這篇文章主要為大家介紹了使用Vite+Vue3+Vant全家桶快速構(gòu)建項目步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-06-06vue?使用el-table循環(huán)輪播數(shù)據(jù)列表的實現(xiàn)
這篇文章主要介紹了vue?使用el-table循環(huán)輪播數(shù)據(jù)列表的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04項目遷移vite引入圖片資源報require?is?not?defined問題的解決辦法
這篇文章主要給大家介紹了關(guān)于項目遷移vite引入圖片資源報require?is?not?defined問題的解決辦法,文中通過代碼介紹的非常詳細,對大家學習或者使用vite具有一定的參考借鑒價值,需要的朋友可以參考下2024-01-01