File tree 3 files changed +48
-4
lines changed
3 files changed +48
-4
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,25 @@ __markdown content__
47
47
48
48
~~~
49
49
50
+ ### With options
51
+ If you have a lot of tabbed sections in your documentation you might want
52
+ to see all of them switch together when one is changed.
53
+ To enable this behavior, just set the ` sync ` option to ` true ` :
54
+
55
+ ``` js
56
+ module .exports = {
57
+ // Your remaining configuration ...
58
+ plugins: [
59
+ [
60
+ ' vuepress-plugin-element-tabs' ,
61
+ {
62
+ sync: true ,
63
+ },
64
+ ],
65
+ ],
66
+ }
67
+ ```
68
+
50
69
## Documents
51
70
> Accepted Value Like That
52
71
~~~ md
Original file line number Diff line number Diff line change 1
1
const path = require ( 'path' )
2
2
3
3
module . exports = ( options , context ) => ( {
4
+ extendPageData ( $page ) {
5
+ $page . elementTabsOptions = options
6
+ } ,
4
7
enhanceAppFiles : [
5
8
path . resolve ( __dirname , './lib/client.js' )
6
9
] ,
@@ -9,8 +12,8 @@ module.exports = (options, context) => ({
9
12
} ,
10
13
chainMarkdown ( config ) {
11
14
config
12
- . plugin ( '@superbiger/tabs' )
13
- . use ( require ( './lib/markdownItPlugin' ) , [ options ] )
14
- . end ( )
15
+ . plugin ( '@superbiger/tabs' )
16
+ . use ( require ( './lib/markdownItPlugin' ) , [ options ] )
17
+ . end ( )
15
18
}
16
19
} )
Original file line number Diff line number Diff line change 7
7
},
8
8
props: {
9
9
type: String ,
10
- activeName: String ,
10
+ activeName: {
11
+ type: String ,
12
+ default () {
13
+ if (typeof localStorage !== ' undefined' ) {
14
+ return localStorage .getItem (' vuepress-plugin-element-tabs@activeId' );
15
+ }
16
+ }
17
+ },
11
18
closable: Boolean ,
12
19
addable: Boolean ,
13
20
value: {},
65
72
handleTabClick (tab , tabName , event ) {
66
73
if (tab .disabled ) return ;
67
74
this .setCurrentName (tabName);
75
+ if (Array .every ([
76
+ this .$page .elementTabsOptions ,
77
+ this .$page .elementTabsOptions .sync ,
78
+ typeof localStorage !== ' undefined'
79
+ ])) {
80
+ localStorage .setItem (' vuepress-plugin-element-tabs@activeId' , tabName);
81
+ }
68
82
this .$emit (' tab-click' , tab, event );
83
+ this .$root .$emit (' tab-change' , tabName, tab, event );
69
84
},
70
85
handleTabRemove (pane , ev ) {
71
86
if (pane .disabled ) return ;
162
177
},
163
178
164
179
created () {
180
+ if (this .$page .elementTabsOptions .sync ) {
181
+ this .$root .$on (' tab-change' , (tabName , tab , event ) => {
182
+ this .setCurrentName (tabName)
183
+ });
184
+ } else if (typeof localStorage !== ' undefined' ) {
185
+ localStorage .removeItem (' vuepress-plugin-element-tabs@activeId' )
186
+ }
165
187
if (! this .currentName ) {
166
188
this .setCurrentName (' 0' );
167
189
}
You can’t perform that action at this time.
0 commit comments