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 | <template> | 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 | <Table :columns="columns1" :data="data1"></Table> | 4 | <Table :columns="columns1" :data="data1"></Table> |
| 5 | </Tab-pane> | 5 | </Tab-pane> |
| 6 | <Tab-pane label="标签二" name="name2"> | 6 | <Tab-pane label="标签二" name="name2"> |
| @@ -15,6 +15,12 @@ | @@ -15,6 +15,12 @@ | ||
| 15 | export default { | 15 | export default { |
| 16 | data () { | 16 | data () { |
| 17 | return { | 17 | return { |
| 18 | + label1: (h) => { | ||
| 19 | + return h('div', [ | ||
| 20 | + h('span', '标签一'), | ||
| 21 | + h('Button', 'button') | ||
| 22 | + ]); | ||
| 23 | + }, | ||
| 18 | columns1: [ | 24 | columns1: [ |
| 19 | { | 25 | { |
| 20 | title: '姓名', | 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 | \ No newline at end of file | 31 | \ No newline at end of file |
src/components/tabs/tabs.vue
| @@ -8,7 +8,8 @@ | @@ -8,7 +8,8 @@ | ||
| 8 | <div :class="barClasses" :style="barStyle"></div> | 8 | <div :class="barClasses" :style="barStyle"></div> |
| 9 | <div :class="tabCls(item)" v-for="(item, index) in navList" @click="handleChange(index)"> | 9 | <div :class="tabCls(item)" v-for="(item, index) in navList" @click="handleChange(index)"> |
| 10 | <Icon v-if="item.icon !== ''" :type="item.icon"></Icon> | 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 | <Icon v-if="showClose(item)" type="ios-close-empty" @click.native.stop="handleRemove(index)"></Icon> | 13 | <Icon v-if="showClose(item)" type="ios-close-empty" @click.native.stop="handleRemove(index)"></Icon> |
| 13 | </div> | 14 | </div> |
| 14 | </div> | 15 | </div> |
| @@ -22,6 +23,7 @@ | @@ -22,6 +23,7 @@ | ||
| 22 | </template> | 23 | </template> |
| 23 | <script> | 24 | <script> |
| 24 | import Icon from '../icon/icon.vue'; | 25 | import Icon from '../icon/icon.vue'; |
| 26 | + import Render from '../base/render.vue'; | ||
| 25 | import { oneOf, getStyle } from '../../utils/assist'; | 27 | import { oneOf, getStyle } from '../../utils/assist'; |
| 26 | import Emitter from '../../mixins/emitter'; | 28 | import Emitter from '../../mixins/emitter'; |
| 27 | 29 | ||
| @@ -30,7 +32,7 @@ | @@ -30,7 +32,7 @@ | ||
| 30 | export default { | 32 | export default { |
| 31 | name: 'Tabs', | 33 | name: 'Tabs', |
| 32 | mixins: [ Emitter ], | 34 | mixins: [ Emitter ], |
| 33 | - components: { Icon }, | 35 | + components: { Icon, Render }, |
| 34 | props: { | 36 | props: { |
| 35 | value: { | 37 | value: { |
| 36 | type: [String, Number] | 38 | type: [String, Number] |
| @@ -128,6 +130,7 @@ | @@ -128,6 +130,7 @@ | ||
| 128 | this.navList = []; | 130 | this.navList = []; |
| 129 | this.getTabs().forEach((pane, index) => { | 131 | this.getTabs().forEach((pane, index) => { |
| 130 | this.navList.push({ | 132 | this.navList.push({ |
| 133 | + labelType: typeof pane.label, | ||
| 131 | label: pane.label, | 134 | label: pane.label, |
| 132 | icon: pane.icon || '', | 135 | icon: pane.icon || '', |
| 133 | name: pane.currentName || index, | 136 | name: pane.currentName || index, |