iview Table根據(jù)權(quán)限顯示對(duì)應(yīng)列

在網(wǎng)上找了很多 沒有看到實(shí)用的方法
研究出來以后決定寫一個(gè)教程 方便大家和自己以后開發(fā)

首先下面是示例圖
示例圖.png
然后貼html代碼
html.png
<!-- 多選 -->
            <div class="fl">
                <checkbox-group v-model="cheackList" @on-change="cheackChange">
                    <checkbox label="在線總?cè)藬?shù)"></checkbox>
                    <checkbox label="在線注冊(cè)人數(shù)"></checkbox>
                    <checkbox label="在線游客"></checkbox>
                </checkbox-group>
            </div>
 <!-- 數(shù)據(jù)表展示 -->
            <div class="exhibition-table" v-if="userExhibition">
                <i-table  :columns="userNumberSet" :data="userNumberList"></i-table>
                <!-- 分頁 -->
                <div class="journalism-page">
                    <page :total="tabPage.Total" show-elevator :current="tabPage.Page" :page-size="tabPage.PageSize"
                        @on-change="changePage" />
                </div>
            </div>
Js代碼(圖) -data數(shù)據(jù)
data數(shù)據(jù).png
Js代碼 -data數(shù)據(jù)
 cheackList: ['在線總?cè)藬?shù)', '在線注冊(cè)人數(shù)', '在線游客'],//多選框參數(shù)
                userNumberSet: [ //表格設(shè)置  
                    {
                        title: '時(shí)間',
                        key: 'Date',
                        sortable: true
                    },
                    {
                        title: '在線總?cè)藬?shù)',
                        key: 'Total',
                    },
                    {
                        title: '在線注冊(cè)人數(shù)',
                        key: 'Users',
                        sortable: true
                    },
                    {
                        title: '在線游客',
                        key: 'Visitors'
                    }
                ],
                userNumberList: [],//表格列表數(shù)據(jù),
                userNumberObj: {//多選框控制表格設(shè)置
                    '在線總?cè)藬?shù)': {
                        title: '在線總?cè)藬?shù)',
                        key: 'Total',
                        sortable: true
                    }, '在線注冊(cè)人數(shù)': {
                        title: '在線注冊(cè)人數(shù)',
                        key: 'Users',
                    }, '在線游客': {
                        title: '在線游客',
                        key: 'Visitors'
                    }
                },
Js代碼(圖) -methods數(shù)據(jù)
methods數(shù)據(jù).png
Js代碼 -methods數(shù)據(jù)
//根據(jù)多選框 展示對(duì)應(yīng)的表格數(shù)據(jù)
            cheackChange: function (type) {
                //每次多選框點(diǎn)擊觸發(fā)事件 初始化table表格設(shè)置的數(shù)組
                //我這里是固定有一個(gè)欄目的 時(shí)間 所以默認(rèn)寫在上面 沒有可以就[]
                this.userNumberSet = [ 
                    {
                        title: '時(shí)間',
                        key: 'Date',
                        sortable: true
                    }

                ],
                //用map方法獲取到被選中的所有item參數(shù) 
                type.map((item, index) => {
                    console.log(item, index);
                    console.log(item, index);
                    //并且根據(jù)參數(shù)拿到userNumberObj先前列好的格式 把被選中的參數(shù)push進(jìn)去
                    this.userNumberSet.push(this.userNumberObj[item])
                })
                console.log(this.userNumberSet);
            },

ok 完工啦

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容