|
1 |
| -# Compatible with Vue |
| 1 | +# Vue compatibility |
2 | 2 |
|
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.js](https://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. |
4 | 4 |
|
5 |
| -## Basic usage |
6 |
| - |
7 |
| -Load the Vue in `./index.html`. |
| 5 | +To get started, load either the production (minified) or development (unminified) version of Vue in your `index.html`: |
8 | 6 |
|
9 | 7 | ```html
|
10 |
| -<script src="//cdn.jsdelivr.net/npm/vue"></script> |
11 |
| -<script src="//cdn.jsdelivr.net/npm/docsify"></script> |
| 8 | +<!-- Production (minified) --> |
| 9 | +<script src="//cdn.jsdelivr.net/npm/vue@2/dist/vue.min.js"></script> |
12 | 10 |
|
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> |
| 11 | +<!-- Development (unminified, with debugging info via console) --> |
| 12 | +<script src="//cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> |
16 | 13 | ```
|
17 | 14 |
|
18 |
| -Then you can immediately write Vue code at Markdown file. `new Vue({ el: '#main' })` script is executed by default to create instance. |
19 |
| - |
20 |
| -*README.md* |
| 15 | +## Basic rendering |
21 | 16 |
|
22 |
| -````markdown |
23 |
| -# Vue guide |
| 17 | +Docsify will automatically render basic Vue content that does not require `data`, `methods`, or other instance features. |
24 | 18 |
|
25 |
| -`v-for` usage. |
| 19 | +```markdown |
| 20 | +<button v-on:click.native="this.alert('Hello, World!')">Say Hello</button> |
26 | 21 |
|
27 |
| -```html |
28 | 22 | <ul>
|
29 |
| - <li v-for="i in 10">{{ i }}</li> |
| 23 | + <li v-for="i in 3">{{ i }}</li> |
30 | 24 | </ul>
|
31 | 25 | ```
|
32 | 26 |
|
| 27 | +The HTML above will render the following: |
| 28 | + |
| 29 | +<button v-on:click="this.alert('Hello, World!')">Say Hello</button> |
| 30 | + |
33 | 31 | <ul>
|
34 |
| - <li v-for="i in 10">{{ i }}</li> |
| 32 | + <li v-for="i in 3">{{ i }}</li> |
35 | 33 | </ul>
|
36 |
| -```` |
37 | 34 |
|
38 |
| -You can manually initialize a Vue instance. |
| 35 | +## Advanced usage |
39 | 36 |
|
40 |
| -*README.md* |
| 37 | +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. |
41 | 38 |
|
42 | 39 | ```markdown
|
43 |
| -# Vue demo |
| 40 | +<div id="example-1"> |
| 41 | + <p>{{ message }}</p> |
| 42 | + |
| 43 | + <button v-on:click="hello">Say Hello</button> |
44 | 44 |
|
45 |
| -<div id="main">hello {{ msg }}</div> |
| 45 | + <button v-on:click="counter -= 1">-</button> |
| 46 | + {{ counter }} |
| 47 | + <button v-on:click="counter += 1">+</button> |
| 48 | +</div> |
| 49 | +``` |
46 | 50 |
|
| 51 | +```markdown |
47 | 52 | <script>
|
48 | 53 | new Vue({
|
49 |
| - el: '#main', |
50 |
| - data: { msg: 'Vue' } |
51 |
| - }) |
| 54 | + el: "#example-1", |
| 55 | + data: function() { |
| 56 | + counter: 0, |
| 57 | + message: "Hello, World!" |
| 58 | + }, |
| 59 | + methods: { |
| 60 | + hello: function() { |
| 61 | + alert(this.message); |
| 62 | + } |
| 63 | + } |
| 64 | + }); |
52 | 65 | </script>
|
53 | 66 | ```
|
54 | 67 |
|
55 |
| -!> In a Markdown file, only the script within the first script tag is executed. |
| 68 | +The HTML & JavaScript above will render the following: |
| 69 | + |
| 70 | +<div id="example-1"> |
| 71 | + <p>{{ message }}</p> |
| 72 | + |
| 73 | + <button v-on:click="hello">Say Hello</button> |
| 74 | + |
| 75 | + <button v-on:click="counter -= 1">-</button> |
| 76 | + {{ counter }} |
| 77 | + <button v-on:click="counter += 1">+</button> |
| 78 | +</div> |
56 | 79 |
|
57 |
| -## Combine Vuep to write playground |
| 80 | +!> 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. |
58 | 81 |
|
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. |
| 82 | +## Vuep playgrounds |
60 | 83 |
|
61 |
| -*index.html* |
| 84 | +[Vuep](https://github.com/QingWei-Li/vuep) is a Vue component that provides a live editor and preview for Vue content. See the [vuep documentation](https://qingwei-li.github.io/vuep/) for details. |
| 85 | + |
| 86 | +Add Vuep CSS and JavaScript to your `index.html`: |
62 | 87 |
|
63 | 88 | ```html
|
64 |
| -<!-- Inject CSS file --> |
| 89 | +<!-- Vuep CSS --> |
65 | 90 | <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/vuep/dist/vuep.css">
|
66 | 91 |
|
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> |
| 92 | +<!-- Vuep JavaScript --> |
74 | 93 | <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 | 94 | ```
|
77 | 95 |
|
78 |
| -*README.md* |
79 |
| -```markdown |
80 |
| -# Vuep |
| 96 | +Add vuep markup to a markdown file (e.g. `README.md`): |
81 | 97 |
|
82 |
| -<vuep template="#example"></vuep> |
| 98 | +```markdown |
| 99 | +<vuep template="#example-2"></vuep> |
83 | 100 |
|
84 |
| -<script v-pre type="text/x-template" id="example"> |
| 101 | +<script v-pre type="text/x-template" id="example-2"> |
85 | 102 | <template>
|
86 | 103 | <div>Hello, {{ name }}!</div>
|
87 | 104 | </template>
|
88 | 105 |
|
89 | 106 | <script>
|
90 | 107 | module.exports = {
|
91 |
| - data: function () { |
| 108 | + data: function() { |
92 | 109 | return { name: 'Vue' }
|
93 | 110 | }
|
94 | 111 | }
|
95 | 112 | </script>
|
96 | 113 | </script>
|
97 | 114 | ```
|
98 | 115 |
|
99 |
| -?> Example Refer to the [Vuep documentation](https://qingwei-li.github.io/vuep/). |
| 116 | +<vuep template="#example-2"></vuep> |
| 117 | + |
| 118 | +<script v-pre type="text/x-template" id="example-2"> |
| 119 | + <template> |
| 120 | + <div>Hello, {{ name }}!</div> |
| 121 | + </template> |
| 122 | + |
| 123 | + <script> |
| 124 | + module.exports = { |
| 125 | + data: function() { |
| 126 | + return { name: 'World' } |
| 127 | + } |
| 128 | + } |
| 129 | + </script> |
| 130 | +</script> |
| 131 | + |
| 132 | +<script> |
| 133 | + new Vue({ |
| 134 | + el: "#example-1", |
| 135 | + data: { |
| 136 | + counter: 0, |
| 137 | + message: "Hello, World!" |
| 138 | + }, |
| 139 | + methods: { |
| 140 | + hello: function() { |
| 141 | + alert(this.message); |
| 142 | + } |
| 143 | + } |
| 144 | + }); |
| 145 | +</script> |
0 commit comments