Skip to content

Commit bd662c4

Browse files
Merge pull request #1409 from docsifyjs/feat/vue-options
feat: Vue components, mount options, global options, and v3 support
2 parents 8ccc202 + ffa7c90 commit bd662c4

22 files changed

+1055
-407
lines changed

Diff for: cypress.json

-3
This file was deleted.

Diff for: docs/configuration.md

+111-10
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ window.$docsify = {
245245
// Custom file name
246246
coverpage: 'cover.md',
247247

248-
// mutiple covers
248+
// multiple covers
249249
coverpage: ['/', '/zh-cn/'],
250250

251-
// mutiple covers and custom file name
251+
// multiple covers and custom file name
252252
coverpage: {
253253
'/': 'cover.md',
254254
'/zh-cn/': 'cover.md',
@@ -410,7 +410,7 @@ window.$docsify = {
410410
};
411411
```
412412

413-
?> If this options is `false` but you dont want to emojify some specific colons , [Refer this](https://github.com/docsifyjs/docsify/issues/742#issuecomment-586313143)
413+
?> If this options is `false` but you don't want to emojify some specific colons , [Refer this](https://github.com/docsifyjs/docsify/issues/742#issuecomment-586313143)
414414

415415
## mergeNavbar
416416

@@ -494,15 +494,15 @@ window.$docsify = {
494494
```
495495

496496
## crossOriginLinks
497-
- type: `Array`
498497

499-
When `routerMode: 'history'`, you may face the cross-origin issues, See [#1379](https://github.com/docsifyjs/docsify/issues/1379).
500-
In Markdown content, there is a simple way to solve it, see extends Markdown syntax `Cross-Origin link` in [helpers](helpers.md).
498+
- type: `Array`
499+
500+
When `routerMode: 'history'`, you may face the cross-origin issues, See [#1379](https://github.com/docsifyjs/docsify/issues/1379).
501+
In Markdown content, there is a simple way to solve it, see extends Markdown syntax `Cross-Origin link` in [helpers](helpers.md).
502+
501503
```js
502504
window.$docsify = {
503-
crossOriginLinks:[
504-
"https://example.com/cross-origin-link",
505-
],
505+
crossOriginLinks: ['https://example.com/cross-origin-link'],
506506
};
507507
```
508508

@@ -604,7 +604,7 @@ window.$docsify = {
604604
};
605605
```
606606

607-
Load the right 404 page according to the localisation:
607+
Load the right 404 page according to the localization:
608608

609609
```js
610610
window.$docsify = {
@@ -629,3 +629,104 @@ window.$docsify = {
629629
topMargin: 90, // default: 0
630630
};
631631
```
632+
633+
## vueComponents
634+
635+
- type: `Object`
636+
637+
Creates and registers global [Vue components](https://vuejs.org/v2/guide/components.html). Components are specified using the component name as the key with an object containing Vue options as the value. Component `data` is unique for each instance and will not persist as users navigate the site.
638+
639+
```js
640+
window.$docsify = {
641+
vueComponents: {
642+
'button-counter': {
643+
template: `
644+
<button @click="count += 1">
645+
You clicked me {{ count }} times
646+
</button>
647+
`,
648+
data() {
649+
return {
650+
count: 0,
651+
};
652+
},
653+
},
654+
},
655+
};
656+
```
657+
658+
```markdown
659+
<button-counter></button-counter>
660+
```
661+
662+
<output data-lang="output">
663+
<button-counter></button-counter>
664+
</output>
665+
666+
## vueGlobalOptions
667+
668+
- type: `Object`
669+
670+
Specifies [Vue options](https://vuejs.org/v2/api/#Options-Data) for use with Vue content not explicitly mounted with [vueMounts](#mounting-dom-elements), [vueComponents](#components), or a [markdown script](#markdown-script). Changes to global `data` will persist and be reflected anywhere global references are used.
671+
672+
```js
673+
window.$docsify = {
674+
vueGlobalOptions: {
675+
data() {
676+
return {
677+
count: 0,
678+
};
679+
},
680+
},
681+
};
682+
```
683+
684+
```markdown
685+
<p>
686+
<button @click="count -= 1">-</button>
687+
{{ count }}
688+
<button @click="count += 1">+</button>
689+
</p>
690+
```
691+
692+
<output data-lang="output">
693+
<p>
694+
<button @click="count -= 1">-</button>
695+
{{ count }}
696+
<button @click="count += 1">+</button>
697+
</p>
698+
</output>
699+
700+
## vueMounts
701+
702+
- type: `Object`
703+
704+
Specifies DOM elements to mount as [Vue instances](https://vuejs.org/v2/guide/instance.html) and their associated options. Mount elements are specified using a [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors) as the key with an object containing Vue options as their value. Docsify will mount the first matching element in the main content area each time a new page is loaded. Mount element `data` is unique for each instance and will not persist as users navigate the site.
705+
706+
```js
707+
window.$docsify = {
708+
vueMounts: {
709+
'#counter': {
710+
data() {
711+
return {
712+
count: 0,
713+
};
714+
},
715+
},
716+
},
717+
};
718+
```
719+
720+
```markdown
721+
<div id="counter">
722+
<button @click="count -= 1">-</button>
723+
{{ count }}
724+
<button @click="count += 1">+</button>
725+
</div>
726+
```
727+
728+
<output id="counter">
729+
<button @click="count -= 1">-</button>
730+
{{ count }}
731+
<button @click="count += 1">+</button>
732+
</output>

Diff for: docs/index.html

+57
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,62 @@
101101
'/': 'Search',
102102
},
103103
},
104+
vueComponents: {
105+
'button-counter': {
106+
template: `
107+
<button @click="count += 1">
108+
You clicked me {{ count }} times
109+
</button>
110+
`,
111+
data() {
112+
return {
113+
count: 0,
114+
};
115+
},
116+
},
117+
},
118+
vueGlobalOptions: {
119+
data() {
120+
return {
121+
count: 0,
122+
message: 'Hello, World!',
123+
// Fake API response
124+
images: [
125+
{ title: 'Image 1', url: 'https://picsum.photos/150?random=1' },
126+
{ title: 'Image 2', url: 'https://picsum.photos/150?random=2' },
127+
{ title: 'Image 3', url: 'https://picsum.photos/150?random=3' },
128+
],
129+
};
130+
},
131+
computed: {
132+
timeOfDay() {
133+
const date = new Date();
134+
const hours = date.getHours();
135+
136+
if (hours < 12) {
137+
return 'morning';
138+
} else if (hours < 18) {
139+
return 'afternoon';
140+
} else {
141+
return 'evening';
142+
}
143+
},
144+
},
145+
methods: {
146+
hello: function() {
147+
alert(this.message);
148+
},
149+
},
150+
},
151+
vueMounts: {
152+
'#counter': {
153+
data() {
154+
return {
155+
count: 0,
156+
};
157+
},
158+
},
159+
},
104160
plugins: [
105161
function(hook, vm) {
106162
hook.beforeEach(function(html) {
@@ -163,5 +219,6 @@
163219
})();
164220
</script>
165221
<script src="//cdn.jsdelivr.net/npm/vue@2/dist/vue.min.js"></script>
222+
<!-- <script src="//cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script> -->
166223
</body>
167224
</html>

0 commit comments

Comments
 (0)