基于ant-design-vue實(shí)現(xiàn)表格操作按鈕組件
使用效果
先看下默認(rèn)效果
支持按鈕超過一定數(shù)量自動(dòng)放到【更多】下拉按鈕里面
按鈕支持動(dòng)態(tài)控制是否禁用,是否顯示。
下面是一個(gè)代碼示例。
export default Vue.extend({ data() { return { dataSource: [ { id: 1, username: '張三', disabled: 1 }, { id: 2, username: '李四', disabled: 0 }, { id: 3, username: '王二麻子', disabled: 0 }, ] as MyData[], columns: [ // { title: '#', dataIndex: 'id' }, { title: '姓名', dataIndex: 'username' }, { title: '狀態(tài)', dataIndex: 'disabled', customRender: (value: number) => { return value === 0 ? ( <a-tag color="green">啟用</a-tag> ) : ( <a-tag>禁用</a-tag> ); }, }, useActionButtons<MyData>({ align: 'center', title: '操作', limit: 0, showDivider: false, buttons: [ { icon: 'search', text: '查看' }, { icon: 'edit', text: '編輯' }, { text: '禁用', visible: (record) => record.disabled === 0, }, { text: '啟用', visible: (record) => record.disabled === 1, }, { icon: 'message', text(record, index) { return `未讀消息(${record.id.toString()})`; }, }, { icon: 'delete', text: '刪除', disabled: (record) => record.disabled === 0, click: (record, index) => { this.$confirm({ content: `確認(rèn)刪除${record.username}嗎?`, }); }, }, ], }), ], }; }, });
介紹用法
type useActionButtons = (config: ActionButtonsConfig) => Table.Column;
原理就是通過一個(gè)函數(shù),返回了一個(gè)帶customRender
的列的配置。
參數(shù)介紹 函數(shù)聲明
export declare interface ActionButtonsConfig<T> extends Table.Column { limit: number; showDivider: boolean; buttons: Array<ActionButtonsColumnConfig<T>>; }
參數(shù) | 類型 | 描述 |
---|---|---|
limit | number | 設(shè)置一個(gè)數(shù)量,超過該數(shù)量,則展示【更多】下拉按鈕。默認(rèn) 0,表示按鈕將全部展示 |
showDivider | boolean | 是否展示分隔符,默認(rèn)展示 |
buttons | ButtonConfig[] | 要展示的按鈕數(shù)組,具體配置看下面介紹 |
ButtonConfig
參數(shù) | 類型 | 描述 |
---|---|---|
text? | string 或 (record, index) => string | 設(shè)置按鈕文本,同時(shí)支持動(dòng)態(tài)設(shè)置,參數(shù)為當(dāng)前行的相關(guān)數(shù)據(jù) |
icon? | string | 設(shè)置按鈕圖標(biāo) |
click | (record, index) => void | 設(shè)置按鈕點(diǎn)擊事件,參數(shù)為當(dāng)前行的相關(guān)數(shù)據(jù) |
disabled? | (record, index) => boolean | 動(dòng)態(tài)設(shè)置按鈕是否禁用,參數(shù)為當(dāng)前行的相關(guān)數(shù)據(jù) |
visible? | (record, index) => boolean | 動(dòng)態(tài)設(shè)置按鈕是否顯示,參數(shù)為當(dāng)前行的相關(guān)數(shù)據(jù) |
安裝
npm i action-buttons
使用
目前沒有寫任何樣式文件,想修改樣式的話,需要自行在項(xiàng)目處理。
按鈕的根節(jié)點(diǎn)設(shè)置了一個(gè) class="action-buttons"
直接在頁(yè)面引入
import { useActionButtons, ActionButtons } from 'action-buttons';
然后寫到 Table Columns 數(shù)組里面對(duì)應(yīng)位置即可。
雖然導(dǎo)出了組件ActionButtons
,但還是推薦直接使用提供的useActionButtons
方法直接去配置表格的操作列。
源碼 https://github.com/Tickly/action-buttons
以上就是基于ant-design-vue實(shí)現(xiàn)表格操作按鈕組件的詳細(xì)內(nèi)容,更多關(guān)于ant-design-vue表格操作按鈕的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
vue中的this.$refs,this.$emit,this.$store,this.$nextTick的使用方式
這篇文章主要介紹了vue中的this.$refs,this.$emit,this.$store,this.$nextTick的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-04-04Vue3根據(jù)動(dòng)態(tài)字段綁定v-model的操作代碼
最近在學(xué)習(xí)vue技術(shù),開發(fā)表格的時(shí)候,想把表格做成組件,那查詢條件就需要?jiǎng)討B(tài)生成,這就遇到一個(gè)問題,vue怎么動(dòng)態(tài)給v-model變量值,本文通過實(shí)例代碼給大家介紹,對(duì)Vue3動(dòng)態(tài)綁定v-model實(shí)例代碼感興趣的朋友一起看看吧2022-10-10uniapp實(shí)現(xiàn)APP、小程序與webview頁(yè)面間通訊的實(shí)現(xiàn)步驟
這篇文章主要介紹了uniapp實(shí)現(xiàn)APP、小程序與webview頁(yè)面間通訊的實(shí)現(xiàn)步驟,在Uniapp開發(fā)的APP或小程序頁(yè)面中嵌入一個(gè)H5網(wǎng)頁(yè),并實(shí)現(xiàn)H5頁(yè)面與APP之間的數(shù)據(jù)傳遞,需要的朋友可以參考下2025-01-01Vue3引入騰訊地圖包含標(biāo)注簡(jiǎn)易操作指南
這篇文章主要介紹了Vue3引入騰訊地圖的相關(guān)資料,并實(shí)現(xiàn)點(diǎn)擊地圖添加標(biāo)注的功能,示例代碼提供了添加單個(gè)或多個(gè)標(biāo)注的方法,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-09-09Vue 利用指令實(shí)現(xiàn)禁止反復(fù)發(fā)送請(qǐng)求的兩種方法
這篇文章主要介紹了Vue 利用指令實(shí)現(xiàn)禁止反復(fù)發(fā)送請(qǐng)求的兩種方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09詳解如何實(shí)現(xiàn)一個(gè)簡(jiǎn)單的 vuex
本篇文章主要介紹了如何實(shí)現(xiàn)一個(gè)簡(jiǎn)單的 vuex,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-02-02解決vuex數(shù)據(jù)頁(yè)面刷新后初始化操作
這篇文章主要介紹了解決vuex數(shù)據(jù)頁(yè)面刷新后初始化操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07vue-router實(shí)現(xiàn)webApp切換頁(yè)面動(dòng)畫效果代碼
本篇文章主要介紹了vue實(shí)現(xiàn)app頁(yè)面切換效果實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-05-05