Commit 1f974700deabaed164cea2fbd1f08e8bcc50caf4
1 parent
eae3e936
Tabs support render head
Showing
3 changed files
with
43 additions
and
4 deletions
Show diff stats
examples/routers/tabs.vue
1 | 1 | <template> |
2 | - <Tabs value="name1" :animated="false"> | |
3 | - <Tab-pane label="标签一" name="name1"> | |
2 | + <Tabs value="name1" :animated="true"> | |
3 | + <Tab-pane :label="label1" name="name1"> | |
4 | 4 | <Table :columns="columns1" :data="data1"></Table> |
5 | 5 | </Tab-pane> |
6 | 6 | <Tab-pane label="标签二" name="name2"> |
... | ... | @@ -15,6 +15,12 @@ |
15 | 15 | export default { |
16 | 16 | data () { |
17 | 17 | return { |
18 | + label1: (h) => { | |
19 | + return h('div', [ | |
20 | + h('span', '标签一'), | |
21 | + h('Button', 'button') | |
22 | + ]); | |
23 | + }, | |
18 | 24 | columns1: [ |
19 | 25 | { |
20 | 26 | title: '姓名', | ... | ... |
1 | +<template> | |
2 | + <div ref="cell"></div> | |
3 | +</template> | |
4 | +<script> | |
5 | + import Vue from 'vue'; | |
6 | + export default { | |
7 | + name: 'RenderCell', | |
8 | + props: { | |
9 | + render: Function | |
10 | + }, | |
11 | + methods: { | |
12 | + compile () { | |
13 | + if (this.render) { | |
14 | + this.$el.innerHTML = ''; | |
15 | + const component = new Vue({ | |
16 | + functional: true, | |
17 | + render: (h) => { | |
18 | + return this.render(h); | |
19 | + } | |
20 | + }); | |
21 | + const Cell = component.$mount(); | |
22 | + this.$refs.cell.appendChild(Cell.$el); | |
23 | + } | |
24 | + } | |
25 | + }, | |
26 | + mounted () { | |
27 | + this.compile(); | |
28 | + } | |
29 | + }; | |
30 | +</script> | |
0 | 31 | \ No newline at end of file | ... | ... |
src/components/tabs/tabs.vue
... | ... | @@ -8,7 +8,8 @@ |
8 | 8 | <div :class="barClasses" :style="barStyle"></div> |
9 | 9 | <div :class="tabCls(item)" v-for="(item, index) in navList" @click="handleChange(index)"> |
10 | 10 | <Icon v-if="item.icon !== ''" :type="item.icon"></Icon> |
11 | - {{ item.label }} | |
11 | + <Render v-if="item.labelType === 'function'" :render="item.label"></Render> | |
12 | + <template v-else>{{ item.label }}</template> | |
12 | 13 | <Icon v-if="showClose(item)" type="ios-close-empty" @click.native.stop="handleRemove(index)"></Icon> |
13 | 14 | </div> |
14 | 15 | </div> |
... | ... | @@ -22,6 +23,7 @@ |
22 | 23 | </template> |
23 | 24 | <script> |
24 | 25 | import Icon from '../icon/icon.vue'; |
26 | + import Render from '../base/render.vue'; | |
25 | 27 | import { oneOf, getStyle } from '../../utils/assist'; |
26 | 28 | import Emitter from '../../mixins/emitter'; |
27 | 29 | |
... | ... | @@ -30,7 +32,7 @@ |
30 | 32 | export default { |
31 | 33 | name: 'Tabs', |
32 | 34 | mixins: [ Emitter ], |
33 | - components: { Icon }, | |
35 | + components: { Icon, Render }, | |
34 | 36 | props: { |
35 | 37 | value: { |
36 | 38 | type: [String, Number] |
... | ... | @@ -128,6 +130,7 @@ |
128 | 130 | this.navList = []; |
129 | 131 | this.getTabs().forEach((pane, index) => { |
130 | 132 | this.navList.push({ |
133 | + labelType: typeof pane.label, | |
131 | 134 | label: pane.label, |
132 | 135 | icon: pane.icon || '', |
133 | 136 | name: pane.currentName || index, | ... | ... |