This commit is contained in:
梁灏 2017-07-17 17:05:10 +08:00
parent fded311fa5
commit 8b530b1ce3
3 changed files with 133 additions and 153 deletions

View file

@ -1,16 +1,40 @@
<template> <template>
<div>{{ row.name }}</div> <Select v-model="model1" style="width:200px">
<Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option>
</Select>
</template> </template>
<script> <script>
export default { export default {
props: { data () {
row: Object return {
cityList: [
{
value: 'beijing',
label: '北京市'
}, },
mounted () { {
// console.log(1); value: 'shanghai',
label: '上海市'
}, },
beforeDestroy () { {
// console.log(2); value: 'shenzhen',
label: '深圳市'
},
{
value: 'hangzhou',
label: '杭州市'
},
{
value: 'nanjing',
label: '南京市'
},
{
value: 'chongqing',
label: '重庆市'
}
],
model1: ''
}
} }
} }
</script> </script>

View file

@ -1,158 +1,114 @@
<template> <template>
<div> <Table width="550" border highlight-row @on-selection-change="change2" @on-current-change="change1" :columns="columns2" :data="data3"></Table>
<div style="margin: 10px">
显示边框 <i-switch v-model="showBorder" style="margin-right: 5px"></i-switch>
显示斑马纹 <i-switch v-model="showStripe" style="margin-right: 5px"></i-switch>
显示索引 <i-switch v-model="showIndex" style="margin-right: 5px"></i-switch>
显示多选框 <i-switch v-model="showCheckbox" style="margin-right: 5px"></i-switch>
显示表头 <i-switch v-model="showHeader" style="margin-right: 5px"></i-switch>
表格滚动 <i-switch v-model="fixedHeader" style="margin-right: 5px"></i-switch>
<br>
<br>
表格尺寸
<Radio-group v-model="tableSize" type="button">
<Radio label="large"></Radio>
<Radio label="default"></Radio>
<Radio label="small"></Radio>
</Radio-group>
</div>
<Table :border="showBorder" :stripe="showStripe" :show-header="showHeader" :height="fixedHeader ? 250 : ''" :size="tableSize" :data="tableData3" :columns="tableColumns3"></Table>
</div>
</template> </template>
<script> <script>
export default { export default {
data () { data () {
return { return {
tableData3: [ columns2: [
{ {
name: '王小明',
age: 18,
address: '北京市朝阳区芍药居',
date: '2016-10-03'
},
{
name: '张小刚',
age: 24,
address: '北京市海淀区西二旗',
date: '2016-10-01'
},
{
name: '李小红',
age: 30,
address: '上海市浦东新区世纪大道',
date: '2016-10-02'
},
{
name: '周小伟',
age: 26,
address: '深圳市南山区深南大道',
date: '2016-10-04'
},
{
name: '王小明',
age: 18,
address: '北京市朝阳区芍药居',
date: '2016-10-03'
},
{
name: '张小刚',
age: 24,
address: '北京市海淀区西二旗',
date: '2016-10-01'
},
{
name: '李小红',
age: 30,
address: '上海市浦东新区世纪大道',
date: '2016-10-02'
},
{
name: '周小伟',
age: 26,
address: '深圳市南山区深南大道',
date: '2016-10-04'
}
],
showBorder: false,
showStripe: false,
showHeader: true,
showIndex: true,
showCheckbox: false,
fixedHeader: false,
tableSize: 'default'
}
},
computed: {
tableColumns3 () {
let columns = [];
if (this.showCheckbox) {
columns.push({
type: 'selection', type: 'selection',
width: 60, width: 60,
align: 'center' align: 'center'
}) },
} {
if (this.showIndex) {
columns.push({
type: 'index',
width: 60,
align: 'center'
})
}
columns.push({
title: '日期',
key: 'date',
sortable: true
});
columns.push({
title: '姓名', title: '姓名',
key: 'name' key: 'name',
}); width: 100,
columns.push({ fixed: 'left'
},
{
title: '年龄', title: '年龄',
key: 'age', key: 'age',
sortable: true, width: 100
filters: [ },
{ {
label: '大于25岁', title: '省份',
value: 1 key: 'province',
width: 100
},
{
title: '市区',
key: 'city',
width: 100
}, },
{ {
label: '小于25岁',
value: 2
}
],
filterMultiple: false,
filterMethod (value, row) {
if (value === 1) {
return row.age > 25;
} else if (value === 2) {
return row.age < 25;
}
}
});
columns.push({
title: '地址', title: '地址',
key: 'address', key: 'address',
filters: [ width: 200
{
label: '北京',
value: '北京'
}, },
{ {
label: '上海', title: '邮编',
value: '上海' key: 'zip',
width: 100
}, },
{ {
label: '深圳', title: '操作',
value: '深圳' key: 'action',
fixed: 'right',
width: 120,
render: (h, params) => {
return h('div', [
h('Button', {
props: {
type: 'text',
size: 'small'
}
}, '查看'),
h('Button', {
props: {
type: 'text',
size: 'small'
}
}, '编辑')
]);
}
} }
], ],
filterMethod (value, row) { data3: [
return row.address.indexOf(value) > -1; {
name: '王小明',
age: 18,
address: '北京市朝阳区芍药居',
province: '北京市',
city: '朝阳区',
zip: 100000
},
{
name: '张小刚',
age: 25,
address: '北京市海淀区西二旗',
province: '北京市',
city: '海淀区',
zip: 100000
},
{
name: '李小红',
age: 30,
address: '上海市浦东新区世纪大道',
province: '上海市',
city: '浦东新区',
zip: 100000
},
{
name: '周小伟',
age: 26,
address: '深圳市南山区深南大道',
province: '广东',
city: '南山区',
zip: 100000
} }
}); ]
return columns; }
},
methods: {
change1 (d, l) {
// console.log(d)
// console.log(l)
},
change2 (d, l) {
console.log(d);
console.log(l);
} }
} }
} }

View file

@ -11,7 +11,7 @@
:prefix-cls="prefixCls" :prefix-cls="prefixCls"
@mouseenter.native.stop="handleMouseIn(row._index)" @mouseenter.native.stop="handleMouseIn(row._index)"
@mouseleave.native.stop="handleMouseOut(row._index)" @mouseleave.native.stop="handleMouseOut(row._index)"
@click.native.stop="clickCurrentRow(row._index)" @click.native="clickCurrentRow(row._index)"
@dblclick.native.stop="dblclickCurrentRow(row._index)"> @dblclick.native.stop="dblclickCurrentRow(row._index)">
<td v-for="column in columns" :class="alignCls(column, row)"> <td v-for="column in columns" :class="alignCls(column, row)">
<Cell <Cell