33 :class =" classes"
44 class =" mdc-drawer"
55 @MDCDrawer:closed =" onClosed"
6+ @MDCDrawer:opened =" onOpened"
67 >
7- <slot name =" header" />
8+ <div
9+ v-if =" !hasHeaderClass || title !== '' || subtitle !== ''"
10+ class =" mdc-drawer__header"
11+ >
12+ <h3
13+ v-if =" title !== ''"
14+ class =" mdc-drawer__title"
15+ >
16+ {{ title }}
17+ </h3 >
18+ <h6
19+ v-if =" subtitle !== ''"
20+ class =" mdc-drawer__subtitle"
21+ >
22+ {{ subtitle }}
23+ </h6 >
24+ <slot name =" header" />
25+ </div >
26+ <slot
27+ v-else
28+ name =" header"
29+ />
830 <slot />
931 </aside >
1032</template >
@@ -31,11 +53,20 @@ export default {
3153 open: {
3254 type: Boolean ,
3355 default: false
56+ },
57+ title: {
58+ type: String ,
59+ default: ' '
60+ },
61+ subtitle: {
62+ type: String ,
63+ default: ' '
3464 }
3565 },
3666 data () {
3767 return {
38- mdcDrawer: undefined
68+ mdcDrawer: undefined ,
69+ hasHeaderClass: false
3970 }
4071 },
4172 computed: {
@@ -56,17 +87,39 @@ export default {
5687 },
5788 watch: {
5889 modal () {
59- if (! this .mdcDrawer ) this .mdcDrawer = new MDCDrawer (this .$el )
90+ if (! this .modal ) {
91+ this .mdcDrawer .destroy ()
92+ this .mdcDrawer = undefined
93+ } else {
94+ this .$nextTick (function () {
95+ this .mdcDrawer = new MDCDrawer (this .$el )
96+ })
97+ }
6098 },
6199 dismissible () {
62- if (! this .mdcDrawer ) this .mdcDrawer = new MDCDrawer (this .$el )
100+ if (! this .dismissible ) {
101+ this .mdcDrawer .destroy ()
102+ this .mdcDrawer = undefined
103+ } else {
104+ this .$nextTick (function () {
105+ this .mdcDrawer = new MDCDrawer (this .$el )
106+ })
107+ }
63108 },
64109 open () {
65- this .mdcDrawer .open = this .open
110+ if (this .mdcDrawer .open !== this .open ) this .mdcDrawer .open = this .open
111+ },
112+ ' mdcDrawer.open ' : function () {
113+ this .model = this .mdcDrawer .open
66114 }
67115 },
68116 mounted () {
69- if (! this .mdcDrawer && (this .dismissible || this .modal )) { this .mdcDrawer = new MDCDrawer (this .$el ) }
117+ // the slots can only be accessible in nextTick
118+ this .$nextTick (function () {
119+ // judge whether the slots have the header class
120+ this .hasHeaderClass = this .$slots .header [0 ].elm .classList .contains (' mdc-drawer__header' )
121+ if (! this .mdcDrawer && (this .dismissible || this .modal )) { this .mdcDrawer = new MDCDrawer (this .$el ) }
122+ })
70123 },
71124 provide: {
72125 mdcDrawer: this
@@ -76,8 +129,11 @@ export default {
76129 },
77130 methods: {
78131 onClosed () {
79- this .model = false
132+ if ( this . model ) this .model = false
80133 this .$emit (' closed' )
134+ },
135+ onOpened () {
136+ this .$emit (' opened' )
81137 }
82138 }
83139}
0 commit comments