欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

VUE element-ui 寫個(gè)復(fù)用Table組件的示例代碼

 更新時(shí)間:2017年11月18日 15:35:10   作者:Shyla  
本篇文章主要介紹了VUE element-ui 寫個(gè)復(fù)用Table組件的示例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

餓了么的table組件功能很強(qiáng)大,對(duì)于項(xiàng)目中的各種表格基本夠用,但是……個(gè)人對(duì)于它以列為單位的操作不習(xí)慣 =。=所以改成了另一種方式(我不會(huì)告訴你其實(shí)本質(zhì)沒變)。

項(xiàng)目中表格較多,所以復(fù)用性最重要

步驟一

先來個(gè)基本的表格展示

官例的tableData

tableData: [{
 date: '2016-05-02',
 name: '王小虎',
 address: '上海市普陀區(qū)金沙江路 1518 弄'
}, {
 date: '2016-05-04',
 name: '王小虎',
 address: '上海市普陀區(qū)金沙江路 1517 弄'
}, {
 date: '2016-05-01',
 name: '王小虎',
 address: '上海市普陀區(qū)金沙江路 1519 弄'
}, {
 date: '2016-05-03',
 name: '王小虎',
 address: '上海市普陀區(qū)金沙江路 1516 弄'
}]

table.vue

<template>
 <el-table :data="tableData" border>
  <el-table-column prop="date" label="日期"></el-table-column>
  <el-table-column prop="name" label="姓名"></el-table-column>
  <el-table-column prop="address" label="地址"></el-table-column>
 </el-table>
</template>

步驟二

簡化一下表格:

//table.vue
<template>
 <el-table :data="tableData" border>
  <el-table-column v-for="(item,key) in tableKey" 
  :key="key"
  :prop="item.value"
  :label="item.name"></el-table-column>
 </el-table>
</template>
<script>
export default{
 name: 'table',
 data(){
  return{
   tableData:[...],
   tableKey: [{
    name: 'date',
    value: '日期'
   },{
    name: '姓名',
    value: 'name'
   },{
    name: '地址',
    value: 'address'
   }]
  }
 }
}
</script>

步驟三

復(fù)用table.vue就是————給它數(shù)據(jù)的同時(shí)告訴它我的字段名唄

新建一個(gè)父組件sl_table.vue

//sl_table.vue
<template>
 <sl-table :tableData="tableData" :tableKey="tableKey"></sl-table>
</template>
<script>
import Table from '@/components/table'
export default{
 name: 'sl-table',
 data(){
  return {
   tableData: [...]
   tableKey: [{
    name: 'date',
    value: '日期'
   },{
    name: '姓名',
    value: 'name'
   },{
    name: '地址',
    value: 'address'
   }]
  }
 },
 components: {
  'sl-table': Table
 }
}
</script>

table.vue就更簡單了

//table.vue
<template>
 <el-table :data="tableData" border>
  <el-table-column v-for="(item,key) in tableKey" 
  :key="key"
  :prop="item.value"
  :label="item.name"></el-table-column>
 </el-table>
</template>
<script>
export default{
 name: 'table',
 data(){
  return{
   
  }
 },
 props:['tableData','tableKey'],
}
</script>

步驟四

可以根據(jù)需求修改table的形式

列寬度

這個(gè)較為簡單,可以直接加個(gè)屬性

//sl_table.vue
...
 data(){
  return {
   tableData: [...]
   tableKey: [{
    name: 'date',
    value: '日期',
    width: 80
   },{
    name: '姓名',
    value: 'name',
    width: 80
   },{
    name: '地址',
    value: 'address'
   }]
  }
 },
...

table.vue

//table.vue
...
<el-table-column v-for="(item,key) in tableKey" 
:key="key"
:prop="item.value"
:label="item.name"
:width="item.width"></el-table-column>
...

自定義模板列

如果我們需要告訴組件哪個(gè)是自定義的列,所以添加一個(gè)屬性operate

table.vue

<el-table-column v-for="(item,key) in tableKey" 
v-if="!item.operate"
:key="key"
:prop="item.value"
:label="item.name"
:width="item.width"></el-table-column>

<!-- 自定義 -->
<el-table-column v-else>
 <template scope="scope">
  <slot :name="item.value" :$index="scope.$index" :row="scope.row"></slot>
 </template>
</el-table-column>
//sl_table.vue
<sl-table :tableData="tableData" :tableKey="tableKey">
 <template slot="date" scope="scope">
  <span>{{ scope.row.date | DateFilter }}</span>
 </template>
</sl-table>
...
  data(){
   return {
    tableData: [...]
    tableKey: [{
     name: 'date',
     value: '日期',
     operate: true
    },{
     name: '姓名',
     value: 'name',
     operate: false
    },{
     name: '地址',
     value: 'address',
     operate: false
    }]
   }
  },
  filters: {
   DateFilter(){...}
  }
...

表格展開行

類似寬度,只要sl_table.vue傳入一個(gè)isExpand的屬性。這里加個(gè)每次只能展開一行的效果:

//sl_table.vue

<sl-table :tableData="tableData" :tableKey="tableKey" :isExpand="true" :isExpandOnly="true">
 <template slot="expand" scope="scope">
  {{...expand something}}
 </template>
 ...
</sl-table>

table.vue

//table.vue
<el-table :data="tableData" border @expand="handleExpand" ref="raw_table">
 <el-table-column v-if="isExpand" type="expand">
  <template scope="scope">
   <slot name="expand" :$index="scope.$index" :row="scope.row"></slot>
  </template>
 </el-table-column>
</el-table>
...
props: ['tableData','tableKey','isExpand','isExpandOnly'],
methods: {
 handleExpand(row,is_expand){
  if(this.isExpand && this.isExpandOnly){
   this.$refs.raw_table.store.states.expandRows = expanded ? [row] : [] 
  }
 }
}

其他的(排序、多選)操作也是類似添加。。。多不贅述。

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue使用NProgress進(jìn)度條的方法

    Vue使用NProgress進(jìn)度條的方法

    這篇文章主要為大家詳細(xì)介紹了Vue使用NProgress進(jìn)度條的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • Vue如何給組件添加點(diǎn)擊事件?@click.native

    Vue如何給組件添加點(diǎn)擊事件?@click.native

    這篇文章主要介紹了Vue如何給組件添加點(diǎn)擊事件?@click.native,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • vue props對(duì)象validator自定義函數(shù)實(shí)例

    vue props對(duì)象validator自定義函數(shù)實(shí)例

    今天小編就為大家分享一篇vue props對(duì)象validator自定義函數(shù)實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • Vue+ElementUi實(shí)現(xiàn)點(diǎn)擊表格中鏈接進(jìn)行頁面跳轉(zhuǎn)與路由詳解

    Vue+ElementUi實(shí)現(xiàn)點(diǎn)擊表格中鏈接進(jìn)行頁面跳轉(zhuǎn)與路由詳解

    在vue中進(jìn)行前端網(wǎng)頁開發(fā)時(shí),通常列表數(shù)據(jù)用el-table展示,下面這篇文章主要給大家介紹了關(guān)于Vue+ElementUi實(shí)現(xiàn)點(diǎn)擊表格中鏈接進(jìn)行頁面跳轉(zhuǎn)與路由的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-02-02
  • Vue 封裝防刷新考試倒計(jì)時(shí)組件的實(shí)現(xiàn)

    Vue 封裝防刷新考試倒計(jì)時(shí)組件的實(shí)現(xiàn)

    這篇文章主要介紹了Vue 封裝防刷新考試倒計(jì)時(shí)組件的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • 離線搭建vue環(huán)境運(yùn)行項(xiàng)目完整步驟

    離線搭建vue環(huán)境運(yùn)行項(xiàng)目完整步驟

    這篇文章主要給大家介紹了關(guān)于離線搭建vue環(huán)境運(yùn)行項(xiàng)目的相關(guān)資料,文中通過實(shí)例代碼以及圖文介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2023-06-06
  • vue的列表交錯(cuò)過渡實(shí)現(xiàn)代碼示例

    vue的列表交錯(cuò)過渡實(shí)現(xiàn)代碼示例

    這篇文章主要介紹了vue的列表交錯(cuò)過渡實(shí)現(xiàn)代碼示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • vue百度地圖 + 定位的詳解

    vue百度地圖 + 定位的詳解

    這篇文章主要介紹了vue百度地圖 + 定位的詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • 詳解Nuxt.js Vue服務(wù)端渲染摸索

    詳解Nuxt.js Vue服務(wù)端渲染摸索

    本篇文章主要介紹了詳解Nuxt.js Vue服務(wù)端渲染摸索,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-02-02
  • vue實(shí)現(xiàn)簡單表格組件實(shí)例詳解

    vue實(shí)現(xiàn)簡單表格組件實(shí)例詳解

    vue的核心思想就是組件,什么是組件呢?按照我的理解組件就是裝配頁面的零件,vue三大核心組件 路由 狀態(tài)管理,路由控制頁面的渲染,頁面由組件組成,數(shù)據(jù)有vuex進(jìn)行管理和改變。下面我會(huì)以一個(gè)簡單的案例來說
    2017-04-04

最新評(píng)論