77<script >
88const props = {
99 duration: {
10- type: Number ,
10+ type: [ Number , Object ] ,
1111 default: 400
1212 },
1313 transition: {
@@ -34,7 +34,7 @@ export default {
3434 this .visible = val
3535 },
3636 visible (val ) {
37- if (this .duration ) {
37+ if (this .toggleTime ) {
3838 this .collapseController (val)
3939 } else {
4040 this .reset ()
@@ -47,17 +47,23 @@ export default {
4747 beforeDestroy () {
4848 clearTimeout (this .heightWatcher )
4949 },
50+ computed: {
51+ toggleTime () {
52+ return (this .visible ? this .duration .show : this .duration .hide ) || this .duration
53+ }
54+ },
5055 methods: {
5156 collapseController (val ) {
5257 if (this .collapsing === false ) {
5358 val ? this .toggle (true ) : this .toggle (false )
54- this .setFinishTimer (this .duration )
59+ this .setFinishTimer (this .toggleTime )
5560 } else {
61+ this .setTransition ()
5662 this .turn ()
5763 const height = Number (this .collapsing .slice (0 ,- 2 ))
5864 const current = this .$el .offsetHeight
5965 const time = (val ? height - current : current) / height
60- this .setFinishTimer (this .duration * time)
66+ this .setFinishTimer (this .toggleTime * time)
6167 }
6268 },
6369 turn () {
@@ -72,10 +78,13 @@ export default {
7278 this .collapsing = this .$el .scrollHeight + ' px'
7379 this .$el .style .height = val ? 0 : this .$el .scrollHeight + ' px'
7480 this .$el .style .overflow = ' hidden'
75- this .$el . style . transition = ` all ${ this . duration } ms ${ this . transition } `
81+ this .setTransition ()
7682 const self = this
7783 setTimeout (() => { self .$el .style .height = val ? this .collapsing : 0 }, 0 )
7884 },
85+ setTransition () {
86+ this .$el .style .transition = ` all ${ this .toggleTime } ms ${ this .transition } `
87+ },
7988 setFinishTimer (duration ) {
8089 clearTimeout (this .heightWatcher )
8190 this .heightWatcher = setTimeout (() => this .reset (), duration)
0 commit comments