element-ui el-dialog嵌套table組件,ref問題及解決
element-ui el-dialog嵌套table組件,ref問題
項(xiàng)目中有個(gè)需求
彈窗顯示的時(shí)候,返現(xiàn)數(shù)據(jù)需要選中,看了elementui table組件中的方法
傳入需要需要選中的行和是否選中的狀態(tài),調(diào)用的時(shí)候肯定是需要增加ref的
this.$refs.moviesTable.toggleRowSelection(this.$refs.moviesTable.data[想要選中行的下標(biāo)],true)
但是在彈窗顯示的時(shí)候這樣用,會(huì)報(bào)錯(cuò),(this.$refs.moviesTable為undefined)
解決辦法
使用替換$nextTick
companyChange 彈窗顯示的方法,selectArr 是需要選中的數(shù)據(jù)數(shù)組,tableData是列表數(shù)據(jù)
vue組件庫(kù) element-ui常見問題總結(jié)
ps: 以下改變element-ui默認(rèn)的樣式時(shí)都不能加scoped,可以加一個(gè)唯一前綴避免污染全局樣式
改變默認(rèn)樣式都可以通過打開控制臺(tái)查看層級(jí)和類名進(jìn)行更改
el-table相關(guān)
1. 改變hover時(shí)表格的背景顏色
? .el-table .el-table__body-wrapper .el-table__body tr.el-table__row:hover > td{ ? ? ? background-color: #ffffff !important; ? } ? //less預(yù)處理器 ? .el-table--enable-row-hover{ ? ? ? .el-table__body{ ? ? ? ? tr:hover>td{ ? ? ? ? ? background-color: #ffffff !important; ? ? ? ? } ? ? ? } ? ? }
2. 改變表格表頭高度及樣式
.el-table__header tr,.el-table__header th { ? ? ? padding: 0; ? ? ? height: 40px; ? }
3. 改變表格內(nèi)容高度及樣式
.el-table__body tr,.el-table__body td { ? ? ? height: 60px; }
4. 改變加邊框表格的邊框顏色
.el-table td, .el-table th.is-leaf,.el-table--border, .el-table--group{ ? ? border-color: #BFBFBF; }
可以自行添加hover時(shí)的顏色
5. 表格的多行合并(避免出現(xiàn)合并后某一行高度撐開)
arraySpanMethod ({ row, column, rowIndex, columnIndex }) { ? if (columnIndex === 0 || columnIndex === 1 || columnIndex === 4) { ? ? ?if (rowIndex % this.gridData.length === 0) { ? ? ? ?return [this.tableData.length, 1] ? ? ?} else { ? ? ? ?return [0, 0] ? ? ?} ? ?} ?},
從需求的最后一行開始向上合并可以解決這個(gè)問題
6. 改變表格表頭樣式的幾種方法
直接添加header-cell-style
<el-table ?v-loading="loading" ?@row-click="rowMeth" ?:data="this.isSearched ? this.searchedData : this.tableData" ?style="width: 100%" ?:header-cell-style="{'color':'#606266','backgroundColor':'#F5F5F5','font-size':'13px','font-weight':500}" ?@selection-change="handleSelectionChange" >
CSS樣式(不能添加scoped)
.el-table__header tr,.el-table__header th { ? ? padding: 0; ? ? height: 40px; }
通過方法改變(更靈活,可以分開操作不同列的表頭)
<el-table ? ? ?ref="multipleTable" ? ? ?:data="tableDatas.docList" ? ? ?tooltip-effect="dark" ? ? ?style="width: 100%" ? ? ?:header-cell-style="getRowClass" ? ? ?@selection-change="handleSelectionChange" > // js方法 getRowClass({ row, column, rowIndex, columnIndex }) { ? ? ? if (rowIndex === 0 && columnIndex === 0) { ? ? ? ? return "background-color:#E8E9EA;font-size:13px;border-top-left-radius: 5px"; ? ? ? } ? ? ? if (rowIndex === 0 && columnIndex === 5) { ? ? ? ? return "background-color:#E8E9EA;color:#606266;border-top-right-radius: 5px "; ? ? ? } ? ? ? if (rowIndex === 0 && columnIndex === 1) { ? ? ? ? return "background-color:#E8E9EA;color:#303133;"; ? ? ? } ? ? ? if (rowIndex === 0 && 1 < columnIndex < 5) { ? ? ? ? return "background-color:#E8E9EA;color:#606266"; ? ? ? } ? ? },
7. 添加表格外邊框
.el-tabs .payContent .el-table { ? border-right: 1px solid #e8e9ea; ? border-left: 1px solid #e8e9ea; ? border-radius: 5px; ? margin-top: 20px; }
payContent 為唯一前綴,避免去除scoped后污染全局樣式
8. 點(diǎn)擊獲取某一行的數(shù)據(jù)
綁定row-click
<el-table ?v-loading="loading" ?@row-click="rowMeth" ?:data="this.isSearched ? this.searchedData : this.tableData" ?style="width: 100%" ?:header-cell-style="{'color':'#606266','backgroundColor':'#F5F5F5','font-size':'13px','font-weight':500}" ?@selection-change="handleSelectionChange" > // js rowMeth (row, column, event) { ? ? console.log(row) },
el-form 表單相關(guān)
1. 改變輸入框的大小高度尺寸
通過element自帶的size屬性進(jìn)行更改
<el-input ? placeholder="請(qǐng)輸入內(nèi)容" ? suffix-icon="el-icon-date" ? v-model="input1"> </el-input> <el-input ? size="medium" ? placeholder="請(qǐng)輸入內(nèi)容" ? suffix-icon="el-icon-date" ? v-model="input2"> </el-input>
通過css自行定義寬高
.inputClass { ? ?.el-input__inner { ? ? ?width: 240px; ? ? ?height: 40px; ? ?} ?}
inputClass 為避免污染全局樣式的唯一前綴
2. element表單驗(yàn)證
<el-form :inline="true" :model="formData" :rules="rules" ?ref="ruleForm1"> // js rules: { ? name: [ ? ? { required: true, message: '請(qǐng)輸入活動(dòng)名稱', trigger: 'blur' }, ? ? { min: 3, max: 5, message: '長(zhǎng)度在 3 到 5 個(gè)字符', trigger: 'blur' } ? ], ? region: [ ? ? { required: true, message: '請(qǐng)選擇活動(dòng)區(qū)域', trigger: 'change' } ? ] }
自定義驗(yàn)證規(guī)則
rules: { ? age: [{ ? ? validator: (rule, value, callback) => { ? ? ? if (value !== '') { ? ? ? ? if ((/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/).test(value) === false) { ? ? ? ? ? callback(new Error('請(qǐng)輸入數(shù)字')) ? ? ? ? } else { ? ? ? ? ? callback() ? ? ? ? } ? ? ? } else { ? ? ? ? callback() ? ? ? } ? ? }, ? ? type: 'number', ? ? trigger: 'change' ? }] }
el-dialog對(duì)話框內(nèi)嵌自定義內(nèi)容的樣式更改
ps: 嵌套在表格中的對(duì)話框無(wú)法打開可以添加:append-to-body="true"顯示
title文字
.el-dialog__title{ ? ? somestyle ? }
header
.el-dialog__header { ?? ?somestyle ? }
content
.el-dialog__body{ ? ? somestyle ? }
footer
.el-dialog__footer{ ?? ?somestyle ? }
整體內(nèi)容
.el-dialog{ ?? ?somestyle }
ps:再重申一次,改變element-ui的默認(rèn)樣式時(shí)不能添加scoped進(jìn)行限制,并且應(yīng)該自定義唯一前綴來(lái)避免污染全局樣式
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Element的穿梭框數(shù)據(jù)量大時(shí)點(diǎn)擊全選卡頓的解決方案
本文主要介紹了Element的穿梭框數(shù)據(jù)量大時(shí)點(diǎn)擊全選卡頓的解決方案,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10Vue如何調(diào)用接口請(qǐng)求頭增加參數(shù)
這篇文章主要介紹了Vue如何調(diào)用接口請(qǐng)求頭增加參數(shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01Vue插槽slot詳細(xì)介紹(對(duì)比版本變化,避免踩坑)
Vue中的Slot對(duì)于編寫可復(fù)用可擴(kuò)展的組件是再合適不過了,下面這篇文章主要給大家介紹了關(guān)于Vue插槽slot詳細(xì)介紹的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06Vue中textarea自適應(yīng)高度方案的實(shí)現(xiàn)
本文主要介紹了Vue中textarea自適應(yīng)高度方案的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01Vue如何在CSS中使用data定義的數(shù)據(jù)淺析
這篇文章主要給大家介紹了關(guān)于Vue如何在CSS中使用data定義的數(shù)據(jù)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-05-05vue+highcharts實(shí)現(xiàn)3D餅圖效果
這篇文章主要為大家詳細(xì)介紹了vue+highcharts實(shí)現(xiàn)3D餅圖效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03Vue2.0學(xué)習(xí)之詳解Vue 組件及父子組件通信
本篇文章主要介紹了Vue2.0學(xué)習(xí)之詳解Vue 組件及父子組件通信,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2017-12-12