-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix inability to instantiate reactive Vue components by 1) handling each child of #main instead of #main itself and 2) skipping elements that are already Vue instances - Retain previous behavior of processing basic Vue rendering without the need for a markdown <script> tag. - Update documentation and add live Vue examples - Update `index.html` files to include Vue.js and Vuep (CSS+JS)
- Loading branch information
1 parent
c78cb11
commit f385e21
Showing
4 changed files
with
126 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,145 @@ | ||
# Compatible with Vue | ||
# Vue compatibility | ||
|
||
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. | ||
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. | ||
|
||
## Basic usage | ||
|
||
Load the Vue in `./index.html`. | ||
To get started, load either the production (minified) or development (unminified) version of Vue in your `index.html`: | ||
|
||
```html | ||
<script src="//cdn.jsdelivr.net/npm/vue"></script> | ||
<script src="//cdn.jsdelivr.net/npm/docsify"></script> | ||
<!-- Production (minified) --> | ||
<script src="//cdn.jsdelivr.net/npm/vue@2/dist/vue.min.js"></script> | ||
|
||
<!-- Or use the compressed files --> | ||
<script src="//cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script> | ||
<script src="//cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js"></script> | ||
<!-- Development (unminified, with debugging info via console) --> | ||
<script src="//cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> | ||
``` | ||
|
||
Then you can immediately write Vue code at Markdown file. `new Vue({ el: '#main' })` script is executed by default to create instance. | ||
|
||
*README.md* | ||
## Basic rendering | ||
|
||
````markdown | ||
# Vue guide | ||
Docsify will automatically render basic Vue content that does not require `data`, `methods`, or other instance features. | ||
|
||
`v-for` usage. | ||
```markdown | ||
<button v-on:click.native="this.alert('Hello, World!')">Say Hello</button> | ||
|
||
```html | ||
<ul> | ||
<li v-for="i in 10">{{ i }}</li> | ||
<li v-for="i in 3">{{ i }}</li> | ||
</ul> | ||
``` | ||
|
||
The HTML above will render the following: | ||
|
||
<button v-on:click="this.alert('Hello, World!')">Say Hello</button> | ||
|
||
<ul> | ||
<li v-for="i in 10">{{ i }}</li> | ||
<li v-for="i in 3">{{ i }}</li> | ||
</ul> | ||
```` | ||
|
||
You can manually initialize a Vue instance. | ||
## Advanced usage | ||
|
||
*README.md* | ||
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. | ||
|
||
```markdown | ||
# Vue demo | ||
<div id="example-1"> | ||
<p>{{ message }}</p> | ||
|
||
<button v-on:click="hello">Say Hello</button> | ||
|
||
<div id="main">hello {{ msg }}</div> | ||
<button v-on:click="counter -= 1">-</button> | ||
{{ counter }} | ||
<button v-on:click="counter += 1">+</button> | ||
</div> | ||
``` | ||
|
||
```markdown | ||
<script> | ||
new Vue({ | ||
el: '#main', | ||
data: { msg: 'Vue' } | ||
}) | ||
el: "#example-1", | ||
data: function() { | ||
counter: 0, | ||
message: "Hello, World!" | ||
}, | ||
methods: { | ||
hello: function() { | ||
alert(this.message); | ||
} | ||
} | ||
}); | ||
</script> | ||
``` | ||
|
||
!> In a Markdown file, only the script within the first script tag is executed. | ||
The HTML & JavaScript above will render the following: | ||
|
||
<div id="example-1"> | ||
<p>{{ message }}</p> | ||
|
||
<button v-on:click="hello">Say Hello</button> | ||
|
||
<button v-on:click="counter -= 1">-</button> | ||
{{ counter }} | ||
<button v-on:click="counter += 1">+</button> | ||
</div> | ||
|
||
## Combine Vuep to write playground | ||
!> 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. | ||
|
||
[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. | ||
## Vuep playgrounds | ||
|
||
*index.html* | ||
[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. | ||
|
||
Add Vuep CSS and JavaScript to your `index.html`: | ||
|
||
```html | ||
<!-- Inject CSS file --> | ||
<!-- Vuep CSS --> | ||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/vuep/dist/vuep.css"> | ||
|
||
<!-- Inject JavaScript file --> | ||
<script src="//cdn.jsdelivr.net/npm/vue"></script> | ||
<script src="//cdn.jsdelivr.net/npm/vuep"></script> | ||
<script src="//cdn.jsdelivr.net/npm/docsify"></script> | ||
|
||
<!-- or use the compressed files --> | ||
<script src="//cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script> | ||
<!-- Vuep JavaScript --> | ||
<script src="//cdn.jsdelivr.net/npm/vuep/dist/vuep.min.js"></script> | ||
<script src="//cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js"></script> | ||
``` | ||
|
||
*README.md* | ||
```markdown | ||
# Vuep | ||
Add vuep markup to a markdown file (e.g. `README.md`): | ||
|
||
<vuep template="#example"></vuep> | ||
```markdown | ||
<vuep template="#example-2"></vuep> | ||
|
||
<script v-pre type="text/x-template" id="example"> | ||
<script v-pre type="text/x-template" id="example-2"> | ||
<template> | ||
<div>Hello, {{ name }}!</div> | ||
</template> | ||
|
||
<script> | ||
module.exports = { | ||
data: function () { | ||
data: function() { | ||
return { name: 'Vue' } | ||
} | ||
} | ||
</script> | ||
</script> | ||
``` | ||
|
||
?> Example Refer to the [Vuep documentation](https://qingwei-li.github.io/vuep/). | ||
<vuep template="#example-2"></vuep> | ||
|
||
<script v-pre type="text/x-template" id="example-2"> | ||
<template> | ||
<div>Hello, {{ name }}!</div> | ||
</template> | ||
|
||
<script> | ||
module.exports = { | ||
data: function() { | ||
return { name: 'World' } | ||
} | ||
} | ||
</script> | ||
</script> | ||
|
||
<script> | ||
new Vue({ | ||
el: "#example-1", | ||
data: { | ||
counter: 0, | ||
message: "Hello, World!" | ||
}, | ||
methods: { | ||
hello: function() { | ||
alert(this.message); | ||
} | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters