Commit cec324522580b31925091ccca37e2786068137de
merge
Showing
5 changed files
with
152 additions
and
38 deletions
Show diff stats
1 | +<template> | |
2 | + <div>{{ name }}</div> | |
3 | +</template> | |
4 | +<script> | |
5 | + export default { | |
6 | + props: { | |
7 | + name: String | |
8 | + }, | |
9 | + created () { | |
10 | + console.log(this.name + ': 被创建'); | |
11 | + }, | |
12 | + destroyed () { | |
13 | + console.log(this.name + ': 被销毁'); | |
14 | + } | |
15 | + } | |
16 | +</script> | |
0 | 17 | \ No newline at end of file | ... | ... |
1 | +<template> | |
2 | + <Table border :columns="columns7" :data="data6" @on-expand="expand"></Table> | |
3 | +</template> | |
4 | +<script> | |
5 | + import TableExpand from '../components/tableExpand.vue'; | |
6 | + import etable from '../components/table.vue'; | |
7 | + export default { | |
8 | + components: { etable }, | |
9 | + data () { | |
10 | + return { | |
11 | + columns7: [ | |
12 | + { | |
13 | + type: 'expand', | |
14 | + width: 50, | |
15 | + render: (h, params) => { | |
16 | +// return h(etable); | |
17 | +// return h('div', params.row.name) | |
18 | + return h(TableExpand, { props: { name: params.row.name } }) | |
19 | + } | |
20 | + }, | |
21 | + { | |
22 | + title: '姓名', | |
23 | + key: 'name', | |
24 | + render: (h, params) => { | |
25 | + return h('div', [ | |
26 | + h('Icon', { | |
27 | + props: { | |
28 | + type: 'person' | |
29 | + } | |
30 | + }), | |
31 | + h('strong', params.row.name) | |
32 | + ]); | |
33 | + } | |
34 | + }, | |
35 | + { | |
36 | + title: '年龄', | |
37 | + key: 'age', | |
38 | + sortable: true | |
39 | + }, | |
40 | + { | |
41 | + title: '地址', | |
42 | + key: 'address' | |
43 | + }, | |
44 | + { | |
45 | + title: '操作', | |
46 | + key: 'action', | |
47 | + width: 150, | |
48 | + align: 'center', | |
49 | + render: (h, params) => { | |
50 | + return h('div', [ | |
51 | + h('Button', { | |
52 | + props: { | |
53 | + type: 'primary', | |
54 | + size: 'small' | |
55 | + }, | |
56 | + style: { | |
57 | + marginRight: '5px' | |
58 | + }, | |
59 | + on: { | |
60 | + click: () => { | |
61 | + this.show(params.index) | |
62 | + } | |
63 | + } | |
64 | + }, '查看'), | |
65 | + h('Button', { | |
66 | + props: { | |
67 | + type: 'error', | |
68 | + size: 'small' | |
69 | + }, | |
70 | + on: { | |
71 | + click: () => { | |
72 | + this.remove(params.index) | |
73 | + } | |
74 | + } | |
75 | + }, '删除') | |
76 | + ]); | |
77 | + } | |
78 | + } | |
79 | + ], | |
80 | + data6: [ | |
81 | + { | |
82 | + name: '王小明', | |
83 | + age: 18, | |
84 | + address: '北京市朝阳区芍药居' | |
85 | + }, | |
86 | + { | |
87 | + name: '张小刚', | |
88 | + age: 25, | |
89 | + address: '北京市海淀区西二旗', | |
90 | + _disableExpand: true | |
91 | + }, | |
92 | + { | |
93 | + name: '李小红', | |
94 | + age: 30, | |
95 | + address: '上海市浦东新区世纪大道', | |
96 | + _expanded: true | |
97 | + }, | |
98 | + { | |
99 | + name: '周小伟', | |
100 | + age: 26, | |
101 | + address: '深圳市南山区深南大道' | |
102 | + } | |
103 | + ] | |
104 | + } | |
105 | + }, | |
106 | + methods: { | |
107 | + show (index) { | |
108 | + this.$Modal.info({ | |
109 | + title: '用户信息', | |
110 | + content: `姓名:${this.data6[index].name}<br>年龄:${this.data6[index].age}<br>地址:${this.data6[index].address}` | |
111 | + }) | |
112 | + }, | |
113 | + remove (index) { | |
114 | + this.data6.splice(index, 1); | |
115 | + }, | |
116 | + expand (row, s) { | |
117 | +// console.log(row); | |
118 | +// console.log(s); | |
119 | + } | |
120 | + } | |
121 | + } | |
122 | +</script> | ... | ... |
1 | + | |
2 | +export default { | |
3 | + name: 'TableExpand', | |
4 | + functional: true, | |
5 | + props: { | |
6 | + row: Object, | |
7 | + render: Function, | |
8 | + index: Number, | |
9 | + }, | |
10 | + render: (h, ctx) => { | |
11 | + return ctx.props.render(h, {row: ctx.props.row, index: ctx.props.index}); | |
12 | + } | |
13 | +}; | |
0 | 14 | \ No newline at end of file | ... | ... |
src/components/table/expand.vue deleted
1 | -<template> | |
2 | - <div ref="cell"></div> | |
3 | -</template> | |
4 | -<script> | |
5 | - import Vue from 'vue'; | |
6 | - export default { | |
7 | - name: 'TableExpand', | |
8 | - props: { | |
9 | - row: Object, | |
10 | - render: Function, | |
11 | - index: Number, | |
12 | - }, | |
13 | - methods: { | |
14 | - compile () { | |
15 | - if (this.render) { | |
16 | - this.$el.innerHTML = ''; | |
17 | - const component = new Vue({ | |
18 | - functional: true, | |
19 | - render: (h) => { | |
20 | - return this.render(h, { | |
21 | - row: this.row, | |
22 | - index: this.index | |
23 | - }); | |
24 | - } | |
25 | - }); | |
26 | - const Cell = component.$mount(); | |
27 | - this.$refs.cell.appendChild(Cell.$el); | |
28 | - } | |
29 | - } | |
30 | - }, | |
31 | - mounted () { | |
32 | - this.$nextTick(() => { | |
33 | - this.compile(); | |
34 | - }); | |
35 | - } | |
36 | - }; | |
37 | -</script> | |
38 | 0 | \ No newline at end of file |
src/components/table/table-body.vue