公司有一個(gè)新的需求,點(diǎn)擊ElTableColumn的頭部可以進(jìn)行搜索,這個(gè)功能同事已經(jīng)做出來了,但是使用有些不方便,自己就打算封裝成一個(gè)組件,學(xué)習(xí)一下。
公司主營業(yè)務(wù):成都做網(wǎng)站、網(wǎng)站制作、移動(dòng)網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)推出定州免費(fèi)做網(wǎng)站回饋大家。
ElTableColumn本來是這個(gè)樣子的:
要做成的是這個(gè)樣子:
我直接就放代碼了,挨著挨著說明太多了。
代碼的結(jié)構(gòu):
組件
<!-- ElTableColumnPro.vue --> <template> <el-table-column v-if="visible" :formatter="formatter" :align='align' :prop="prop" :header-align="headerAlign" :label="label" :width="width" :render-header="renderHeader" > <template slot-scope="scope"> <slot :row="scope.row" :$index="scope.$index" > <span>{{fomatMethod(scope.row[prop])}}</span> </slot> </template> </el-table-column> </template> <script> import moment from "moment"; export default { name: "el-table-column-pro", props: { prop: { type: String }, label: { type: String }, width: { type: Number }, renderType: { type: String, validator: value => ["date", "input", "select"].includes(value) }, placeholder: { type: String }, rederWidth: { type: String, default: "230px" }, param: { type: String, default: "" }, startDate: { type: String }, endDate: { type: String }, selectList: { type: Array }, isClear: { type: Boolean, default:true }, visible: { type: Boolean, default: true }, filterIcon: { type: String, default: "el-icon-search" }, callback: { type: Function }, formatter: { type: Function, default:(row, column, cellValue)=>cellValue }, align:{ type:String }, headerAlign:{ type:String } }, data() { return { formatD:this.filterIcon }; }, methods: { fomatMethod(value){ return this.formatter('','',value) }, renderHeader(createElement, { column, $index }) { switch (this.renderType) { case "date": return this.renderDate(createElement, { column, $index }); case "input": return this.rederInput(createElement, { column, $index }); case "select": return this.rederSelect(createElement, { column, $index }); default: return column.label; } }, rederInput(createElement, { column, $index }) { return createElement( "div", { class: "filters", style: { color: column.color } }, [ createElement( "el-popover", { props: { placement: "bottom", width: "200", trigger: "click" } }, [ createElement("el-input", { props: { placeholder: this.placeholder, value: this.param }, nativeOn: { keyup: event => { if (event.keyCode === 13) { this.$emit("update:param", event.target.value); this.callback && this.callback(); } } }, on: { blur: event => { this.$emit("update:param", event.target.value); this.callback && this.callback(); } } }), createElement( "span", { slot: "reference" }, [ column.label, createElement("i", { class: this.filterIcon, style: { marginLeft: "4px" } }) ] ) ] ) ] ); }, rederSelect(createElement, { column, $index }) { return createElement( "div", { class: "filters", style: { color: column.color } }, [ createElement( "el-popover", { props: { placement: "bottom", width: "200", trigger: "click" } }, [ createElement( "el-select", { props: { placeholder: this.placeholder, value: this.param, clearable: this.isClear }, on: { input: value => { this.$emit("update:param", value); this.callback && this.callback(); } } }, [ this.selectList.map(item => { return createElement("el-option", { props: { value: item.value, label: item.label } }); }) ] ), createElement( "span", { slot: "reference" }, [ column.label, createElement("i", { class: this.filterIcon, style: { marginLeft: "4px" } }) ] ) ] ) ] ); }, renderDate(createElement, { column, $index }) { return createElement( "div", { class: "filters" }, [ createElement( "el-popover", { props: { placement: "bottom", width: this.rederWidth, trigger: "click" } }, [ createElement("el-date-picker", { props: { placeholder: this.placeholder, value: this.value, type: "daterange", rangeSeparator:"至", startPlaceholder:"開始日期", endPlaceholder:"結(jié)束日期", }, style: { width: this.rederWidth }, on: { input: value => { if (value) { const startDate = moment(value[0]).format("YYYY-MM-DD"); const endDate = moment(value[1]).format("YYYY-MM-DD"); this.$emit("update:startDate", startDate); this.$emit("update:endDate", endDate); this.callback && this.callback(); } } } }), createElement( "span", { slot: "reference" }, [ column.label, createElement("i", { class: this.filterIcon, style: { marginLeft: "4px" } }) ] ) ] ) ] ); } } }; </script> <!-- index.js --> import ElTableColumnPro from './ElTableColumnPro' ElTableColumnPro.install = function(Vue) { Vue.component(ElTableColumnPro.name, ElTableColumnPro); }; export default ElTableColumnPro;
安裝
import ElTableColumnPro from 'components/ElTableColumnPro/index' ... ... ... Vue.use(ElTableColumnPro)
使用
<el-table :data="bankFlow" stripe> <el-table-column-pro :visible="showMore" prop="transactionId" label="流水號" :width="120"> </el-table-column-pro> <el-table-column-pro prop="clientCode" label="客戶代碼 " :width="120" placeholder="請輸入客戶代碼" :callback="requestTransactionLogs" renderType="input" :param.sync="request_params.clientCode"> </el-table-column-pro> <el-table-column-pro prop="eventTypeName" label="事件 " placeholder="請選擇事件" :selectList="listEventEnum" :callback="requestTransactionLogs" renderType="select" :param.sync="request_params.event" :width="100"> </el-table-column-pro> <el-table-column-pro prop="createTime" :callback="requestTransactionLogs" :startDate.sync="request_params.startDate" :endDate.sync="request_params.endDate" :formatter="$timeformat" label="時(shí)間" renderType="date" :width="180" ></el-table-column-pro> </el-table>
<el-table :data="lists.content" v-loading="loading" @row-dblclick="detail" > <el-table-column-pro :width="120" prop="clientCode" label="客戶代碼 " align="center" header-align="center" placeholder="請輸入客戶代碼" :callback="getLists" renderType="input" :param.sync="params.clientCode"></el-table-column-pro> <el-table-column-pro label="內(nèi)容 " placeholder="請輸入內(nèi)容" :callback="getLists" renderType="input" :param.sync="params.content"> <template slot-scope="scope"> <pre>{{scope.row.content}}</pre> </template> </el-table-column-pro> <el-table-column-pro prop="userName" :width="100" label="記錄人 " align="center" header-align="center" placeholder="請輸入記錄人" :callback="getLists" renderType="input" :param.sync="params.userName"></el-table-column-pro> <el-table-column prop="createTime" width="150" label="記錄時(shí)間" align="center" header-align="center" :formatter="$dateTimeFormat"></el-table-column> </el-table>
注釋就不挨著打了....
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
網(wǎng)站名稱:詳解VUE對element-ui中的ElTableColumn擴(kuò)展
標(biāo)題URL:http://www.rwnh.cn/article36/gpodpg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航、建站公司、小程序開發(fā)、網(wǎng)頁設(shè)計(jì)公司、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)