当前位置: 首页 > Web前端 > HTML5

实现vue的markdown文档可以在线运行

时间:2023-04-05 12:48:48 HTML5

实现vue的markdown文档可以在线运行一个vue组件,用于markdown文档中的vue代码执行,可以边看边执行。Githubhttps://github.com/zhangKunUs...DEMOhttps://zhangkunusergit.github...安装npminstallvue-markdown-run--save用法(一)完整介绍//importimportMarkdownRunfrom'vue-markdown-run';//全局注入Vue.use(MarkdownRun);(2)按需导入借助babel-plugin-component,我们可以只导入需要的组件,达到减小项目体积的目的。首先,安装babel-plugin-component:npminstallbabel-plugin-component-save-dev然后,修改.babelrc为:{"plugins":[["component",{"libraryName":"vue-markdown-run","styleLibraryName":"theme"}]]}接下来,如果只需要导入一些组件,写如下:import{MarkdownRun}from'vue-markdown-run';exportdefault{components:{MarkdownRun}}Component用法参数说明参数值默认值说明:mark必须通过(String)nomarkdowntextstring(具体要求见下文“markdownTxt编写要求”):scopeisnot(Object)nomarkdowntext,导入的组件如果不想全局导入,可以在本地导入。用法请参考看上面的DEMOhighlight-style-file-name不是(String)'github'markdown代码部分样式文件名,这里是指定导入哪个样式(css)文件。详情请参考:https://highlightjs.org/stati。..InStyles:runClassisnot(String)nocssstylenameattheVuerunningcode:runStyleisnot(Object)isnottheinterlinestylenameattheVuerunningcode@errorisnot(Function)不是回调函数当前组件执行失败的markdownTxt的写法要求代码必须指定需要执行哪个组件,在上面写vue-run,否则会认为是普通文本,不会执行。vue-run放在语言类型后面,需要空格,例如:'```htmlvue-run如有问题,请联系邮箱:1766597067@qq.com微信ID:18625531739