Commit bdfab3b99e9b04b992ffd0c4c9051668e88ab96e
1 parent
7b3d5ec1
fixed #1842
Showing
2 changed files
with
85 additions
and
60 deletions
Show diff stats
examples/routers/tabs.vue
1 | +<!--<template>--> | ||
2 | + <!--<Tabs value="name1" :animated="false">--> | ||
3 | + <!--<Tab-pane label="test" name="test">--> | ||
4 | + <!--<Tabs type="card" v-bind:animated="true">--> | ||
5 | + <!--<Tab-pane label="标签2一">标签2一的内容</Tab-pane>--> | ||
6 | + <!--<Tab-pane label="标签2二">标签2二的内容</Tab-pane>--> | ||
7 | + <!--<Tab-pane label="标签2三">标签2三的内容</Tab-pane>--> | ||
8 | + <!--</Tabs>--> | ||
9 | + <!--</Tab-pane>--> | ||
10 | + <!--<Tab-pane :label="label1" name="name1">--> | ||
11 | + <!--<Table :columns="columns1" :data="data1"></Table>--> | ||
12 | + <!--</Tab-pane>--> | ||
13 | + <!--<Tab-pane label="标签二" name="name2">--> | ||
14 | + <!--<Table :columns="columns1" :data="data1"></Table>--> | ||
15 | + <!--</Tab-pane>--> | ||
16 | + <!--<Tab-pane label="标签三" name="name3">--> | ||
17 | + <!--<Table :columns="columns1" :data="data1"></Table>--> | ||
18 | + <!--</Tab-pane>--> | ||
19 | + <!--</Tabs>--> | ||
20 | +<!--</template>--> | ||
21 | +<!--<script>--> | ||
22 | + <!--export default {--> | ||
23 | + <!--data () {--> | ||
24 | + <!--return {--> | ||
25 | + <!--label1: (h) => {--> | ||
26 | + <!--return h('div', [--> | ||
27 | + <!--h('span', '标签一'),--> | ||
28 | + <!--h('Button', 'button')--> | ||
29 | + <!--]);--> | ||
30 | + <!--},--> | ||
31 | + <!--columns1: [--> | ||
32 | + <!--{--> | ||
33 | + <!--title: '姓名',--> | ||
34 | + <!--key: 'name'--> | ||
35 | + <!--},--> | ||
36 | + <!--{--> | ||
37 | + <!--title: '年龄',--> | ||
38 | + <!--key: 'age'--> | ||
39 | + <!--},--> | ||
40 | + <!--{--> | ||
41 | + <!--title: '地址',--> | ||
42 | + <!--key: 'address'--> | ||
43 | + <!--}--> | ||
44 | + <!--],--> | ||
45 | + <!--data1: [--> | ||
46 | + <!--{--> | ||
47 | + <!--name: '王小明',--> | ||
48 | + <!--age: 18,--> | ||
49 | + <!--address: '北京市朝阳区芍药居'--> | ||
50 | + <!--},--> | ||
51 | + <!--{--> | ||
52 | + <!--name: '张小刚',--> | ||
53 | + <!--age: 25,--> | ||
54 | + <!--address: '北京市海淀区西二旗'--> | ||
55 | + <!--},--> | ||
56 | + <!--{--> | ||
57 | + <!--name: '李小红',--> | ||
58 | + <!--age: 30,--> | ||
59 | + <!--address: '上海市浦东新区世纪大道'--> | ||
60 | + <!--},--> | ||
61 | + <!--{--> | ||
62 | + <!--name: '周小伟',--> | ||
63 | + <!--age: 26,--> | ||
64 | + <!--address: '深圳市南山区深南大道'--> | ||
65 | + <!--}--> | ||
66 | + <!--]--> | ||
67 | + <!--}--> | ||
68 | + <!--}--> | ||
69 | + <!--}--> | ||
70 | +<!--</script>--> | ||
71 | + | ||
72 | + | ||
1 | <template> | 73 | <template> |
2 | - <Tabs value="name1" :animated="false"> | ||
3 | - <Tab-pane label="test" name="test"> | ||
4 | - <Tabs type="card" v-bind:animated="true"> | ||
5 | - <Tab-pane label="标签2一">标签2一的内容</Tab-pane> | ||
6 | - <Tab-pane label="标签2二">标签2二的内容</Tab-pane> | ||
7 | - <Tab-pane label="标签2三">标签2三的内容</Tab-pane> | ||
8 | - </Tabs> | ||
9 | - </Tab-pane> | ||
10 | - <Tab-pane :label="label1" name="name1"> | ||
11 | - <Table :columns="columns1" :data="data1"></Table> | ||
12 | - </Tab-pane> | ||
13 | - <Tab-pane label="标签二" name="name2"> | ||
14 | - <Table :columns="columns1" :data="data1"></Table> | ||
15 | - </Tab-pane> | ||
16 | - <Tab-pane label="标签三" name="name3"> | ||
17 | - <Table :columns="columns1" :data="data1"></Table> | ||
18 | - </Tab-pane> | 74 | + <Tabs type="card" closable @on-tab-remove="handleTabRemove"> |
75 | + <TabPane label="标签一" v-if="tab0">标签一的内容</TabPane> | ||
76 | + <TabPane label="标签二" v-if="tab1">标签二的内容</TabPane> | ||
77 | + <TabPane label="标签三" v-if="tab2">标签三的内容</TabPane> | ||
19 | </Tabs> | 78 | </Tabs> |
20 | </template> | 79 | </template> |
21 | <script> | 80 | <script> |
22 | export default { | 81 | export default { |
23 | data () { | 82 | data () { |
24 | return { | 83 | return { |
25 | - label1: (h) => { | ||
26 | - return h('div', [ | ||
27 | - h('span', '标签一'), | ||
28 | - h('Button', 'button') | ||
29 | - ]); | ||
30 | - }, | ||
31 | - columns1: [ | ||
32 | - { | ||
33 | - title: '姓名', | ||
34 | - key: 'name' | ||
35 | - }, | ||
36 | - { | ||
37 | - title: '年龄', | ||
38 | - key: 'age' | ||
39 | - }, | ||
40 | - { | ||
41 | - title: '地址', | ||
42 | - key: 'address' | ||
43 | - } | ||
44 | - ], | ||
45 | - data1: [ | ||
46 | - { | ||
47 | - name: '王小明', | ||
48 | - age: 18, | ||
49 | - address: '北京市朝阳区芍药居' | ||
50 | - }, | ||
51 | - { | ||
52 | - name: '张小刚', | ||
53 | - age: 25, | ||
54 | - address: '北京市海淀区西二旗' | ||
55 | - }, | ||
56 | - { | ||
57 | - name: '李小红', | ||
58 | - age: 30, | ||
59 | - address: '上海市浦东新区世纪大道' | ||
60 | - }, | ||
61 | - { | ||
62 | - name: '周小伟', | ||
63 | - age: 26, | ||
64 | - address: '深圳市南山区深南大道' | ||
65 | - } | ||
66 | - ] | 84 | + tab0: true, |
85 | + tab1: true, | ||
86 | + tab2: true | ||
87 | + } | ||
88 | + }, | ||
89 | + methods: { | ||
90 | + handleTabRemove (name) { | ||
91 | + this['tab' + name] = false; | ||
67 | } | 92 | } |
68 | } | 93 | } |
69 | } | 94 | } |
src/components/tabs/tabs.vue
@@ -150,7 +150,7 @@ | @@ -150,7 +150,7 @@ | ||
150 | const index = this.navList.findIndex((nav) => nav.name === this.activeKey); | 150 | const index = this.navList.findIndex((nav) => nav.name === this.activeKey); |
151 | const prevTabs = this.$refs.nav.querySelectorAll(`.${prefixCls}-tab`); | 151 | const prevTabs = this.$refs.nav.querySelectorAll(`.${prefixCls}-tab`); |
152 | const tab = prevTabs[index]; | 152 | const tab = prevTabs[index]; |
153 | - this.barWidth = parseFloat(tab.offsetWidth); | 153 | + this.barWidth = tab ? parseFloat(tab.offsetWidth) : 0; |
154 | 154 | ||
155 | if (index > 0) { | 155 | if (index > 0) { |
156 | let offset = 0; | 156 | let offset = 0; |