Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
5fb72444
Commit
5fb72444
authored
Jan 04, 2017
by
baiyaaaaa
Committed by
杨奕
Jan 05, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix dynamic change tabs bug
parent
0c0f2527
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
37 deletions
+41
-37
packages/tabs/src/tab-pane.vue
packages/tabs/src/tab-pane.vue
+3
-2
packages/tabs/src/tabs.vue
packages/tabs/src/tabs.vue
+38
-34
test/unit/specs/tabs.spec.js
test/unit/specs/tabs.spec.js
+0
-1
No files found.
packages/tabs/src/tab-pane.vue
View file @
5fb72444
...
@@ -34,14 +34,15 @@
...
@@ -34,14 +34,15 @@
}
}
},
},
crea
ted
()
{
moun
ted
()
{
this
.
$parent
.
$forceUpdate
(
);
this
.
$parent
.
addPanes
(
this
);
},
},
destroyed
()
{
destroyed
()
{
if
(
this
.
$el
&&
this
.
$el
.
parentNode
)
{
if
(
this
.
$el
&&
this
.
$el
.
parentNode
)
{
this
.
$el
.
parentNode
.
removeChild
(
this
.
$el
);
this
.
$el
.
parentNode
.
removeChild
(
this
.
$el
);
}
}
this
.
$parent
.
removePanes
(
this
);
},
},
watch
:
{
watch
:
{
...
...
packages/tabs/src/tabs.vue
View file @
5fb72444
...
@@ -20,7 +20,8 @@
...
@@ -20,7 +20,8 @@
data
()
{
data
()
{
return
{
return
{
children
:
null
,
children
:
null
,
currentName
:
this
.
value
||
this
.
activeName
currentName
:
this
.
value
||
this
.
activeName
,
panes
:
[]
};
};
},
},
...
@@ -34,16 +35,9 @@
...
@@ -34,16 +35,9 @@
},
},
computed
:
{
computed
:
{
tabPanes
:
{
cache
:
false
,
get
()
{
if
(
!
this
.
$children
)
return
[];
return
this
.
$children
.
filter
(
item
=>
item
.
$options
.
componentName
===
'
ElTabPane
'
);
}
},
currentTab
()
{
currentTab
()
{
let
result
;
let
result
;
this
.
tabP
anes
.
forEach
(
tab
=>
{
this
.
p
anes
.
forEach
(
tab
=>
{
if
(
this
.
currentName
===
(
tab
.
name
||
tab
.
index
))
{
if
(
this
.
currentName
===
(
tab
.
name
||
tab
.
index
))
{
result
=
tab
;
result
=
tab
;
}
}
...
@@ -53,22 +47,25 @@
...
@@ -53,22 +47,25 @@
},
},
methods
:
{
methods
:
{
handleTabRemove
(
tab
,
event
)
{
handleTabRemove
(
pane
,
event
)
{
event
.
stopPropagation
();
event
.
stopPropagation
();
const
tabs
=
this
.
tabP
anes
;
const
panes
=
this
.
p
anes
;
const
currentTab
=
this
.
currentTab
;
const
currentTab
=
this
.
currentTab
;
let
index
=
tabs
.
indexOf
(
tab
);
let
index
=
panes
.
indexOf
(
pane
);
tab
.
$destroy
();
if
(
index
===
-
1
)
return
;
panes
.
splice
(
index
,
1
);
pane
.
$destroy
();
this
.
$emit
(
'
tab-remove
'
,
tab
);
this
.
$emit
(
'
tab-remove
'
,
pane
);
this
.
$forceUpdate
();
this
.
$nextTick
(
_
=>
{
this
.
$nextTick
(
_
=>
{
if
(
tab
.
active
)
{
if
(
pane
.
active
)
{
const
tabs
=
this
.
tabP
anes
;
const
panes
=
this
.
p
anes
;
let
nextChild
=
tab
s
[
index
];
let
nextChild
=
pane
s
[
index
];
let
prevChild
=
tab
s
[
index
-
1
];
let
prevChild
=
pane
s
[
index
-
1
];
let
nextActiveTab
=
nextChild
||
prevChild
||
null
;
let
nextActiveTab
=
nextChild
||
prevChild
||
null
;
if
(
nextActiveTab
)
{
if
(
nextActiveTab
)
{
...
@@ -88,10 +85,17 @@
...
@@ -88,10 +85,17 @@
setCurrentName
(
value
)
{
setCurrentName
(
value
)
{
this
.
currentName
=
value
;
this
.
currentName
=
value
;
this
.
$emit
(
'
input
'
,
value
);
this
.
$emit
(
'
input
'
,
value
);
}
},
},
mounted
()
{
addPanes
(
item
)
{
this
.
$forceUpdate
();
this
.
panes
.
push
(
item
);
},
removePanes
(
item
)
{
const
panes
=
this
.
panes
;
const
index
=
panes
.
indexOf
(
item
);
if
(
index
>
-
1
)
{
panes
.
splice
(
index
,
1
);
}
}
},
},
render
(
h
)
{
render
(
h
)
{
let
{
let
{
...
@@ -99,33 +103,33 @@
...
@@ -99,33 +103,33 @@
handleTabRemove
,
handleTabRemove
,
handleTabClick
,
handleTabClick
,
currentName
,
currentName
,
tabP
anes
p
anes
}
=
this
;
}
=
this
;
const
tabs
=
this
.
_l
(
tabPanes
,
(
tab
,
index
)
=>
{
const
tabs
=
this
.
_l
(
panes
,
(
pane
,
index
)
=>
{
let
tabName
=
tab
.
name
||
tab
.
index
||
index
;
let
tabName
=
pane
.
name
||
pane
.
index
||
index
;
if
(
currentName
===
undefined
&&
index
===
0
)
{
if
(
currentName
===
undefined
&&
index
===
0
)
{
this
.
setCurrentName
(
tabName
);
this
.
setCurrentName
(
tabName
);
}
}
tab
.
index
=
index
;
pane
.
index
=
index
;
const
btnClose
=
tab
.
isClosable
const
btnClose
=
pane
.
isClosable
?
<
span
class
=
"
el-icon-close
"
on
-
click
=
{(
ev
)
=>
{
handleTabRemove
(
tab
,
ev
);
}}
><
/span
>
?
<
span
class
=
"
el-icon-close
"
on
-
click
=
{(
ev
)
=>
{
handleTabRemove
(
pane
,
ev
);
}}
><
/span
>
:
null
;
:
null
;
const
tabLabelContent
=
tab
.
$slots
.
label
||
tab
.
label
;
const
tabLabelContent
=
pane
.
$slots
.
label
||
pane
.
label
;
return
(
return
(
<
div
<
div
class
=
{{
class
=
{{
'
el-tabs__item
'
:
true
,
'
el-tabs__item
'
:
true
,
'
is-active
'
:
tab
.
active
,
'
is-active
'
:
pane
.
active
,
'
is-disabled
'
:
tab
.
disabled
,
'
is-disabled
'
:
pane
.
disabled
,
'
is-closable
'
:
tab
.
isClosable
'
is-closable
'
:
pane
.
isClosable
}}
}}
ref
=
"
tabs
"
ref
=
"
tabs
"
refInFor
refInFor
on
-
click
=
{(
ev
)
=>
{
handleTabClick
(
tab
,
tabName
,
ev
);
}}
on
-
click
=
{(
ev
)
=>
{
handleTabClick
(
pane
,
tabName
,
ev
);
}}
>
>
{
tabLabelContent
}
{
tabLabelContent
}
{
btnClose
}
{
btnClose
}
...
@@ -140,7 +144,7 @@
...
@@ -140,7 +144,7 @@
'
el-tabs--border-card
'
:
type
===
'
border-card
'
'
el-tabs--border-card
'
:
type
===
'
border-card
'
}}
>
}}
>
<
div
class
=
"
el-tabs__header
"
>
<
div
class
=
"
el-tabs__header
"
>
{
!
type
?
<
tab
-
bar
tabs
=
{
tabP
anes
}
><
/tab-bar> : null
}
{
!
type
?
<
tab
-
bar
tabs
=
{
p
anes
}
><
/tab-bar> : null
}
{
tabs
}
{
tabs
}
<
/div
>
<
/div
>
<
div
class
=
"
el-tabs__content
"
>
<
div
class
=
"
el-tabs__content
"
>
...
...
test/unit/specs/tabs.spec.js
View file @
5fb72444
...
@@ -63,7 +63,6 @@ describe('Tabs', () => {
...
@@ -63,7 +63,6 @@ describe('Tabs', () => {
const
tabList
=
vm
.
$refs
.
tabs
.
$refs
.
tabs
;
const
tabList
=
vm
.
$refs
.
tabs
.
$refs
.
tabs
;
expect
(
tabList
[
1
].
classList
.
contains
(
'
is-active
'
)).
to
.
be
.
true
;
expect
(
tabList
[
1
].
classList
.
contains
(
'
is-active
'
)).
to
.
be
.
true
;
// expect(vm.$el.querySelector('.el-tabs__active-bar'))
expect
(
paneList
[
1
].
style
.
display
).
to
.
not
.
ok
;
expect
(
paneList
[
1
].
style
.
display
).
to
.
not
.
ok
;
tabList
[
3
].
click
();
tabList
[
3
].
click
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment