实现Vue的markdown文档可以在线运行的方法示例
2019-01-23 12:21
2795 查看
markdown 文档中Vue代码 可执行啦,而且可以边看边执行。这样就可以用markdown文档的形式,写自己的Vue博客了, 可以方便介绍自己的原创组件,很酷的执行。
Github
https://github.com/zhangKunUserGit/vue-markdown-run
DEMO
https://zhangkunusergit.github.io/vue-markdown-run/dist/
安装
npm install vue-markdown-run --save
用法
(1)完整引入
// 引入 import MarkdownRun from 'vue-markdown-run'; // 全局注入 Vue.use(MarkdownRun);
(2)按需引入
借助 babel-plugin-component ,我们可以只引入需要的组件,以达到减小项目体积的目的。
首先,安装 babel-plugin-component:
npm install babel-plugin-component -save-dev
然后,将 .babelrc 修改为:
{ "plugins": [ [ "component", { "libraryName": "vue-markdown-run", "styleLibraryName": "theme" } ] ] }
接下来,如果你只需引入部分组件,写入以下内容:
import { MarkdownRun } from 'vue-markdown-run'; export default { components: { MarkdownRun } }
组件的用法
<markdown-run :mark="markdownTxt" highlight-style-file-name="github" :runClass="" :runStyle="" @error="" />
参数说明
参数 | 值 | 默认值 | 说明 |
---|---|---|---|
:mark | 必传(String) | 无 | markdown文本字符串(具体要求请看下面的“markdownTxt 写法要求”) |
:scope | 非(Object) | 无 | markdown文本中,引入的组件,如果不想全局引入,可以局部引入,用法请看上面的DEMO |
highlight-style-file-name | 非(String) | 'github' | markdown代码部分样式文件名,此处是指定引入那种样式(css)文件 详细请参考:https://highlightjs.org/stati... 中Styles |
:runClass | 非(String) | 无 | Vue运行代码处的css样式名称 |
:runStyle | 非(Object) | 无 | Vue运行代码处的行间样式名称 |
@error | 非(Function) | 无 | 当前组件执行失败的回调函数 |
markdownTxt 写法要求
代码中必须指定哪个组件是需要执行的,在上面写上 vue-run , 否则认为是普通文本,不予执行。
vue-run 放在语言类型后面,需要空格,例如:
```html vue-run <template> <div @click="go">Hello, {{name}}! 你可以点击试试</div> </template> <script> export default { data() { return { name: 'Vue' } }, methods: { go () { alert('点击弹出, 代码vue已执行'); } } } </script> <style> div{ background-color: red; } </style>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章推荐
- vue插件开发之使用pdf.js实现手机端在线预览pdf文档的方法
- asp.net实现word文档在线预览功能的方法
- Vue 组件(component)教程之实现精美的日历方法示例
- 实现pc和手机两终端都可以在线播放视频的一种方法
- Vue多种方法实现表头和首列固定的示例代码
- vue项目tween方法实现返回顶部的示例代码
- vue中如何实现后台管理系统的权限控制的方法示例
- vue+node实现图片上传及预览的示例方法
- java 外部调用c程序(后缀为.exe--是可以运行的程序--不是本地方法的实现)
- vue+socket.io+express+mongodb 实现简易多房间在线群聊示例
- vagrant 使用方法简介 virtualbox 的命令行管理工具 可以实现virtualbox后台运行
- vue权限路由实现的方法示例总结
- asp.net实现word文档在线预览功能的方法
- vue插件开发 使用pdf.js实现手机端在线预览pdf文档
- 类似百度文库的文档在线预览实现方法
- Objective-C运行时编程 - 实现自动化description方法的思路及代码示例
- vue.js实现请求数据的方法示例
- C#编程简单实现生成PDF文档的方法示例
- C#实现将Doc文档转换成rtf格式的方法示例
- Python实现pdf文档转txt的方法示例