Skip to content

Commit 761210c

Browse files
Merge pull request #1271 from docsifyjs/fix-790
Fix Vue Reactivity
2 parents 0ef6aa8 + 4f6148d commit 761210c

File tree

9 files changed

+390
-116
lines changed

9 files changed

+390
-116
lines changed

Diff for: docs/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,6 @@
162162
}
163163
})();
164164
</script>
165+
<script src="//cdn.jsdelivr.net/npm/vue@2/dist/vue.min.js"></script>
165166
</body>
166167
</html>

Diff for: docs/vue.md

+97-59
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,137 @@
1-
# Compatible with Vue
1+
# Vue compatibility
22

3-
You can write Vue components directly in the Markdown file, and it will be parsed. You can use this feature to write vue demo and documentation together.
3+
Docsify allows Vue [v2.x](https://vuejs.org) and [v3.x](https://v3.vuejs.org) components to be added directly to you Markdown files. These components can greatly simplify working with data and adding reactivity to your content.
44

5-
## Basic usage
5+
To get started, load either the production or development version of Vue in your `index.html`:
66

7-
Load the Vue in `./index.html`.
7+
#### Vue 2.x
88

99
```html
10-
<script src="//cdn.jsdelivr.net/npm/vue"></script>
11-
<script src="//cdn.jsdelivr.net/npm/docsify"></script>
10+
<!-- Production -->
11+
<script src="//cdn.jsdelivr.net/npm/vue@2/dist/vue.min.js"></script>
1212

13-
<!-- Or use the compressed files -->
14-
<script src="//cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
15-
<script src="//cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js"></script>
13+
<!-- Development (debugging and Vue.js devtools support) -->
14+
<script src="//cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
1615
```
1716

18-
Then you can immediately write Vue code at Markdown file. `new Vue({ el: '#main' })` script is executed by default to create instance.
17+
#### Vue 3.x
1918

20-
*README.md*
19+
```html
20+
<!-- Production -->
21+
<script src="//cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
22+
23+
<!-- Development (debugging and Vue.js devtools support) -->
24+
<script src="//cdn.jsdelivr.net/npm/vue@3/dist/vue.global.js"></script>
25+
```
2126

22-
````markdown
23-
# Vue guide
27+
## Basic rendering
2428

25-
`v-for` usage.
29+
Docsify will automatically render basic Vue content that does not require `data`, `methods`, or other instance features.
2630

27-
```html
31+
```markdown
2832
<ul>
29-
<li v-for="i in 10">{{ i }}</li>
33+
<li v-for="i in 3">{{ i }}</li>
3034
</ul>
3135
```
3236

37+
The HTML above will render the following:
38+
3339
<ul>
34-
<li v-for="i in 10">{{ i }}</li>
40+
<li v-for="i in 3">{{ i }}</li>
3541
</ul>
36-
````
3742

38-
You can manually initialize a Vue instance.
43+
## Advanced usage
44+
45+
Vue components and templates that require `data`, `methods`, computed properties, lifecycle hooks, etc. require manually creating a new `Vue()` instance within a `<script>` tag in your markdown.
3946

40-
*README.md*
47+
<!-- prettier-ignore-start -->
4148

4249
```markdown
43-
# Vue demo
50+
<div id="example-1">
51+
<p>{{ message }}</p>
4452

45-
<div id="main">hello {{ msg }}</div>
53+
<button v-on:click="hello">Say Hello</button>
4654

55+
<button v-on:click="counter -= 1">-</button>
56+
{{ counter }}
57+
<button v-on:click="counter += 1">+</button>
58+
</div>
59+
```
60+
61+
<!-- prettier-ignore-end -->
62+
63+
#### Vue 2.x
64+
65+
```markdown
4766
<script>
4867
new Vue({
49-
el: '#main',
50-
data: { msg: 'Vue' }
51-
})
68+
el: "#example-1",
69+
data: function() {
70+
return {
71+
counter: 0,
72+
message: "Hello, World!"
73+
};
74+
},
75+
methods: {
76+
hello: function() {
77+
alert(this.message);
78+
}
79+
}
80+
});
5281
</script>
5382
```
5483

55-
!> In a Markdown file, only the script within the first script tag is executed.
84+
#### Vue 3.x
5685

57-
## Combine Vuep to write playground
86+
```markdown
87+
<script>
88+
Vue.createApp({
89+
data: function() {
90+
return {
91+
counter: 0,
92+
message: "Hello, World!"
93+
};
94+
},
95+
methods: {
96+
hello: function() {
97+
alert(this.message);
98+
}
99+
}
100+
}).mount("#example-1");
101+
</script>
102+
```
58103

59-
[Vuep](https://github.com/QingWei-Li/vuep) is a component for rendering Vue components with live editor and preview. Supports Vue component spec and JSX.
104+
The HTML & JavaScript above will render the following:
60105

61-
*index.html*
106+
<!-- prettier-ignore-start -->
62107

63-
```html
64-
<!-- Inject CSS file -->
65-
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/vuep/dist/vuep.css">
66-
67-
<!-- Inject JavaScript file -->
68-
<script src="//cdn.jsdelivr.net/npm/vue"></script>
69-
<script src="//cdn.jsdelivr.net/npm/vuep"></script>
70-
<script src="//cdn.jsdelivr.net/npm/docsify"></script>
71-
72-
<!-- or use the compressed files -->
73-
<script src="//cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
74-
<script src="//cdn.jsdelivr.net/npm/vuep/dist/vuep.min.js"></script>
75-
<script src="//cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js"></script>
76-
```
108+
<div id="example-1">
109+
<p>{{ message }}</p>
77110

78-
*README.md*
79-
```markdown
80-
# Vuep
111+
<button v-on:click="hello">Say Hello</button>
81112

82-
<vuep template="#example"></vuep>
113+
<button v-on:click="counter -= 1">-</button>
114+
{{ counter }}
115+
<button v-on:click="counter += 1">+</button>
116+
</div>
83117

84-
<script v-pre type="text/x-template" id="example">
85-
<template>
86-
<div>Hello, {{ name }}!</div>
87-
</template>
118+
<!-- prettier-ignore-end -->
88119

89-
<script>
90-
module.exports = {
91-
data: function () {
92-
return { name: 'Vue' }
120+
!> Only the first `<script>` tag in a markdown file is executed. If you are working with multiple Vue components, all `Vue` instances must be created within this tag.
121+
122+
<script>
123+
new Vue({
124+
el: "#example-1",
125+
data: function() {
126+
return {
127+
counter: 0,
128+
message: "Hello, World!"
129+
};
130+
},
131+
methods: {
132+
hello: function() {
133+
alert(this.message);
93134
}
94135
}
95-
</script>
136+
});
96137
</script>
97-
```
98-
99-
?> Example Refer to the [Vuep documentation](https://qingwei-li.github.io/vuep/).

Diff for: jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { globals: serverGlobals } = require('./test/config/server.js');
44
const sharedConfig = {
55
errorOnDeprecated: true,
66
globals: {
7-
...serverGlobals, // BLANK_URL, DOCS_URL, LIB_URL, TEST_HOST
7+
...serverGlobals, // BLANK_URL, DOCS_URL, LIB_URL, NODE_MODULES_URL, TEST_HOST
88
DOCS_PATH: path.resolve(__dirname, 'docs'),
99
LIB_PATH: path.resolve(__dirname, 'lib'),
1010
SRC_PATH: path.resolve(__dirname, 'src'),

Diff for: package-lock.json

+96
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
"rollup-plugin-uglify": "^6.0.4",
104104
"serve-handler": "^6.1.2",
105105
"stylus": "^0.54.5",
106+
"vue2": "npm:vue@^2.6.12",
107+
"vue3": "npm:vue@^3.0.0",
106108
"xhr-mock": "^2.5.1"
107109
},
108110
"keywords": [

0 commit comments

Comments
 (0)