• vue-cli3中使用markdown并在markdown中执行vue代码


    一、安装依赖

    yarn add vue-markdown-loader markdown-it markdown-it-container

      yarn add highlight.js

    二、在vue.config.js中引入插件并配置webpack

    const markdownRender = require('markdown-it')()
    module.exports = {
      chainWebpack: (config) => {
        /*  */
        config.module
          .rule('md')
          .test(/.md$/)
          .use('vue-loader')
          .loader('vue-loader')
          .end()
          .use('vue-markdown-loader')
          .loader('vue-markdown-loader/lib/markdown-compiler')
          .options({
            wrapper: 'article',
            wrapperName: '123',
            raw: true,
            preventExtract: true,
            use: [
              [
                require('markdown-it-container'),
                'demo',
                {
                  validate: function (params) {
                    return params.trim().match(/^demos+(.*)$/)
                  },
    
                  render: function (tokens, idx) {
                    if (tokens[idx].nesting === 1) {
                      // 1.获取第一行的内容使用markdown渲染html作为组件的描述
                      let demoInfo = tokens[idx].info.trim().match(/^demos+(.*)$/)
                      let description =
                        demoInfo && demoInfo.length > 1 ? demoInfo[1] : ''
                      let descriptionHTML = description
                        ? markdownRender.render(description)
                        : ''
                      // 2.获取代码块内的html和js代码
                      let content = tokens[idx + 1].content
                      // 3.使用自定义开发组件【DemoBlock】来包裹内容并且渲染成案例和代码示例
                      return `<demo-block>
              <div class="source" slot="source">${content}</div>
              ${descriptionHTML}
              <div class="highlight" slot="highlight">`
                    } else {
                      return '</div></demo-block>
    '
                    }
                  },
                },
              ],
            ],
          })
      },
    }

    三、在assets目录下新建github-markdown.css文件(这个css文件是markdown的样式文件,我从githib上下载到本地来的)

    article .octicon {
        display: inline-block;
        fill: currentColor;
        vertical-align: text-bottom;
    }
    
    article .anchor {
        float: left;
        line-height: 1;
        margin-left: -20px;
        padding-right: 4px;
    }
    
    article .anchor:focus {
        outline: none;
    }
    
    article h1 .octicon-link,
    article h2 .octicon-link,
    article h3 .octicon-link,
    article h4 .octicon-link,
    article h5 .octicon-link,
    article h6 .octicon-link {
        color: #1b1f23;
        vertical-align: middle;
        visibility: hidden;
    }
    
    article h1:hover .anchor,
    article h2:hover .anchor,
    article h3:hover .anchor,
    article h4:hover .anchor,
    article h5:hover .anchor,
    article h6:hover .anchor {
        text-decoration: none;
    }
    
    article h1:hover .anchor .octicon-link,
    article h2:hover .anchor .octicon-link,
    article h3:hover .anchor .octicon-link,
    article h4:hover .anchor .octicon-link,
    article h5:hover .anchor .octicon-link,
    article h6:hover .anchor .octicon-link {
        visibility: visible;
    }
    
    article h1:hover .anchor .octicon-link:before,
    article h2:hover .anchor .octicon-link:before,
    article h3:hover .anchor .octicon-link:before,
    article h4:hover .anchor .octicon-link:before,
    article h5:hover .anchor .octicon-link:before,
    article h6:hover .anchor .octicon-link:before {
         16px;
        height: 16px;
        content: ' ';
        display: inline-block;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' version='1.1' width='16' height='16' aria-hidden='true'%3E%3Cpath fill-rule='evenodd' d='M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z'%3E%3C/path%3E%3C/svg%3E");
    }
    
    article {
        -ms-text-size-adjust: 100%;
        -webkit-text-size-adjust: 100%;
        line-height: 1.5;
        color: #24292e;
        font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;
        font-size: 16px;
        line-height: 1.5;
        word-wrap: break-word;
    }
    
    article details {
        display: block;
    }
    
    article summary {
        display: list-item;
    }
    
    article a {
        background-color: initial;
    }
    
    article a:active,
    article a:hover {
        outline- 0;
    }
    
    article strong {
        font-weight: inherit;
        font-weight: bolder;
    }
    
    article h1 {
        font-size: 2em;
        margin: .67em 0;
    }
    
    article img {
        border-style: none;
    }
    
    article code,
    article kbd,
    article pre {
        font-family: monospace, monospace;
        font-size: 1em;
    }
    
    article hr {
        box-sizing: initial;
        height: 0;
        overflow: visible;
    }
    
    article input {
        font: inherit;
        margin: 0;
    }
    
    article input {
        overflow: visible;
    }
    
    article [type=checkbox] {
        box-sizing: border-box;
        padding: 0;
    }
    
    article * {
        box-sizing: border-box;
    }
    
    article input {
        font-family: inherit;
        font-size: inherit;
        line-height: inherit;
    }
    
    article a {
        color: #0366d6;
        text-decoration: none;
    }
    
    article a:hover {
        text-decoration: underline;
    }
    
    article strong {
        font-weight: 600;
    }
    
    article hr {
        height: 0;
        margin: 15px 0;
        overflow: hidden;
        background: transparent;
        border: 0;
        border-bottom: 1px solid #dfe2e5;
    }
    
    article hr:after,
    article hr:before {
        display: table;
        content: "";
    }
    
    article hr:after {
        clear: both;
    }
    
    article table {
        border-spacing: 0;
        border-collapse: collapse;
    }
    
    article td,
    article th {
        padding: 0;
    }
    
    article details summary {
        cursor: pointer;
    }
    
    article kbd {
        display: inline-block;
        padding: 3px 5px;
        font: 11px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
        line-height: 10px;
        color: #444d56;
        vertical-align: middle;
        background-color: #fafbfc;
        border: 1px solid #d1d5da;
        border-radius: 3px;
        box-shadow: inset 0 -1px 0 #d1d5da;
    }
    
    article h1,
    article h2,
    article h3,
    article h4,
    article h5,
    article h6 {
        margin-top: 0;
        margin-bottom: 0;
    }
    
    article h1 {
        font-size: 32px;
    }
    
    article h1,
    article h2 {
        font-weight: 600;
    }
    
    article h2 {
        font-size: 24px;
    }
    
    article h3 {
        font-size: 20px;
    }
    
    article h3,
    article h4 {
        font-weight: 600;
    }
    
    article h4 {
        font-size: 16px;
    }
    
    article h5 {
        font-size: 14px;
    }
    
    article h5,
    article h6 {
        font-weight: 600;
    }
    
    article h6 {
        font-size: 12px;
    }
    
    article p {
        margin-top: 0;
        margin-bottom: 10px;
    }
    
    article blockquote {
        margin: 0;
    }
    
    article ol,
    article ul {
        padding-left: 0;
        margin-top: 0;
        margin-bottom: 0;
    }
    
    article ol ol,
    article ul ol {
        list-style-type: lower-roman;
    }
    
    article ol ol ol,
    article ol ul ol,
    article ul ol ol,
    article ul ul ol {
        list-style-type: lower-alpha;
    }
    
    article dd {
        margin-left: 0;
    }
    
    article code,
    article pre {
        font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
        font-size: 12px;
    }
    
    article pre {
        margin-top: 0;
        margin-bottom: 0;
    }
    
    article input::-webkit-inner-spin-button,
    article input::-webkit-outer-spin-button {
        margin: 0;
        -webkit-appearance: none;
        appearance: none;
    }
    
    article :checked+.radio-label {
        position: relative;
        z-index: 1;
        border-color: #0366d6;
    }
    
    article .border {
        border: 1px solid #e1e4e8 !important;
    }
    
    article .border-0 {
        border: 0 !important;
    }
    
    article .border-bottom {
        border-bottom: 1px solid #e1e4e8 !important;
    }
    
    article .rounded-1 {
        border-radius: 3px !important;
    }
    
    article .bg-white {
        background-color: #fff !important;
    }
    
    article .bg-gray-light {
        background-color: #fafbfc !important;
    }
    
    article .text-gray-light {
        color: #6a737d !important;
    }
    
    article .mb-0 {
        margin-bottom: 0 !important;
    }
    
    article .my-2 {
        margin-top: 8px !important;
        margin-bottom: 8px !important;
    }
    
    article .pl-0 {
        padding-left: 0 !important;
    }
    
    article .py-0 {
        padding-top: 0 !important;
        padding-bottom: 0 !important;
    }
    
    article .pl-1 {
        padding-left: 4px !important;
    }
    
    article .pl-2 {
        padding-left: 8px !important;
    }
    
    article .py-2 {
        padding-top: 8px !important;
        padding-bottom: 8px !important;
    }
    
    article .pl-3,
    article .px-3 {
        padding-left: 16px !important;
    }
    
    article .px-3 {
        padding-right: 16px !important;
    }
    
    article .pl-4 {
        padding-left: 24px !important;
    }
    
    article .pl-5 {
        padding-left: 32px !important;
    }
    
    article .pl-6 {
        padding-left: 40px !important;
    }
    
    article .f6 {
        font-size: 12px !important;
    }
    
    article .lh-condensed {
        line-height: 1.25 !important;
    }
    
    article .text-bold {
        font-weight: 600 !important;
    }
    
    article .pl-c {
        color: #6a737d;
    }
    
    article .pl-c1,
    article .pl-s .pl-v {
        color: #005cc5;
    }
    
    article .pl-e,
    article .pl-en {
        color: #6f42c1;
    }
    
    article .pl-s .pl-s1,
    article .pl-smi {
        color: #24292e;
    }
    
    article .pl-ent {
        color: #22863a;
    }
    
    article .pl-k {
        color: #d73a49;
    }
    
    article .pl-pds,
    article .pl-s,
    article .pl-s .pl-pse .pl-s1,
    article .pl-sr,
    article .pl-sr .pl-cce,
    article .pl-sr .pl-sra,
    article .pl-sr .pl-sre {
        color: #032f62;
    }
    
    article .pl-smw,
    article .pl-v {
        color: #e36209;
    }
    
    article .pl-bu {
        color: #b31d28;
    }
    
    article .pl-ii {
        color: #fafbfc;
        background-color: #b31d28;
    }
    
    article .pl-c2 {
        color: #fafbfc;
        background-color: #d73a49;
    }
    
    article .pl-c2:before {
        content: "^M";
    }
    
    article .pl-sr .pl-cce {
        font-weight: 700;
        color: #22863a;
    }
    
    article .pl-ml {
        color: #735c0f;
    }
    
    article .pl-mh,
    article .pl-mh .pl-en,
    article .pl-ms {
        font-weight: 700;
        color: #005cc5;
    }
    
    article .pl-mi {
        font-style: italic;
        color: #24292e;
    }
    
    article .pl-mb {
        font-weight: 700;
        color: #24292e;
    }
    
    article .pl-md {
        color: #b31d28;
        background-color: #ffeef0;
    }
    
    article .pl-mi1 {
        color: #22863a;
        background-color: #f0fff4;
    }
    
    article .pl-mc {
        color: #e36209;
        background-color: #ffebda;
    }
    
    article .pl-mi2 {
        color: #f6f8fa;
        background-color: #005cc5;
    }
    
    article .pl-mdr {
        font-weight: 700;
        color: #6f42c1;
    }
    
    article .pl-ba {
        color: #586069;
    }
    
    article .pl-sg {
        color: #959da5;
    }
    
    article .pl-corl {
        text-decoration: underline;
        color: #032f62;
    }
    
    article .mb-0 {
        margin-bottom: 0 !important;
    }
    
    article .my-2 {
        margin-bottom: 8px !important;
    }
    
    article .my-2 {
        margin-top: 8px !important;
    }
    
    article .pl-0 {
        padding-left: 0 !important;
    }
    
    article .py-0 {
        padding-top: 0 !important;
        padding-bottom: 0 !important;
    }
    
    article .pl-1 {
        padding-left: 4px !important;
    }
    
    article .pl-2 {
        padding-left: 8px !important;
    }
    
    article .py-2 {
        padding-top: 8px !important;
        padding-bottom: 8px !important;
    }
    
    article .pl-3 {
        padding-left: 16px !important;
    }
    
    article .pl-4 {
        padding-left: 24px !important;
    }
    
    article .pl-5 {
        padding-left: 32px !important;
    }
    
    article .pl-6 {
        padding-left: 40px !important;
    }
    
    article .pl-7 {
        padding-left: 48px !important;
    }
    
    article .pl-8 {
        padding-left: 64px !important;
    }
    
    article .pl-9 {
        padding-left: 80px !important;
    }
    
    article .pl-10 {
        padding-left: 96px !important;
    }
    
    article .pl-11 {
        padding-left: 112px !important;
    }
    
    article .pl-12 {
        padding-left: 128px !important;
    }
    
    article hr {
        border-bottom-color: #eee;
    }
    
    article kbd {
        display: inline-block;
        padding: 3px 5px;
        font: 11px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
        line-height: 10px;
        color: #444d56;
        vertical-align: middle;
        background-color: #fafbfc;
        border: 1px solid #d1d5da;
        border-radius: 3px;
        box-shadow: inset 0 -1px 0 #d1d5da;
    }
    
    article:after,
    article:before {
        display: table;
        content: "";
    }
    
    article:after {
        clear: both;
    }
    
    article>:first-child {
        margin-top: 0 !important;
    }
    
    article>:last-child {
        margin-bottom: 0 !important;
    }
    
    article a:not([href]) {
        color: inherit;
        text-decoration: none;
    }
    
    article blockquote,
    article details,
    article dl,
    article ol,
    article p,
    article pre,
    article table,
    article ul {
        margin-top: 0;
        margin-bottom: 16px;
    }
    
    article hr {
        height: .25em;
        padding: 0;
        margin: 24px 0;
        background-color: #e1e4e8;
        border: 0;
    }
    
    article blockquote {
        padding: 0 1em;
        color: #6a737d;
        border-left: .25em solid #dfe2e5;
    }
    
    article blockquote>:first-child {
        margin-top: 0;
    }
    
    article blockquote>:last-child {
        margin-bottom: 0;
    }
    
    article h1,
    article h2,
    article h3,
    article h4,
    article h5,
    article h6 {
        margin-top: 24px;
        margin-bottom: 16px;
        font-weight: 600;
        line-height: 1.25;
    }
    
    article h1 {
        font-size: 2em;
    }
    
    article h1,
    article h2 {
        padding-bottom: .3em;
        border-bottom: 1px solid #eaecef;
    }
    
    article h2 {
        font-size: 1.5em;
    }
    
    article h3 {
        font-size: 1.25em;
    }
    
    article h4 {
        font-size: 1em;
    }
    
    article h5 {
        font-size: .875em;
    }
    
    article h6 {
        font-size: .85em;
        color: #6a737d;
    }
    
    article ol,
    article ul {
        padding-left: 2em;
    }
    
    article ol ol,
    article ol ul,
    article ul ol,
    article ul ul {
        margin-top: 0;
        margin-bottom: 0;
    }
    
    article li {
        word-wrap: break-all;
    }
    
    article li>p {
        margin-top: 16px;
    }
    
    article li+li {
        margin-top: .25em;
    }
    
    article dl {
        padding: 0;
    }
    
    article dl dt {
        padding: 0;
        margin-top: 16px;
        font-size: 1em;
        font-style: italic;
        font-weight: 600;
    }
    
    article dl dd {
        padding: 0 16px;
        margin-bottom: 16px;
    }
    
    article table {
        display: block;
         100%;
        overflow: auto;
    }
    
    article table th {
        font-weight: 600;
    }
    
    article table td,
    article table th {
        padding: 6px 13px;
        border: 1px solid #dfe2e5;
    }
    
    article table tr {
        background-color: #fff;
        border-top: 1px solid #c6cbd1;
    }
    
    article table tr:nth-child(2n) {
        background-color: #f6f8fa;
    }
    
    article img {
        max- 100%;
        box-sizing: initial;
        background-color: #fff;
    }
    
    article img[align=right] {
        padding-left: 20px;
    }
    
    article img[align=left] {
        padding-right: 20px;
    }
    
    article code {
        padding: .2em .4em;
        margin: 0;
        font-size: 85%;
        background-color: rgba(27, 31, 35, .05);
        border-radius: 3px;
    }
    
    article pre {
        word-wrap: normal;
    }
    
    article pre>code {
        padding: 0;
        margin: 0;
        font-size: 100%;
        word-break: normal;
        white-space: pre;
        background: transparent;
        border: 0;
    }
    
    article .highlight {
        margin-bottom: 16px;
    }
    
    article .highlight pre {
        margin-bottom: 0;
        word-break: normal;
    }
    
    article .highlight pre,
    article pre {
        padding: 16px;
        overflow: auto;
        font-size: 85%;
        line-height: 1.45;
        background-color: #f6f8fa;
        border-radius: 3px;
    }
    
    article pre code {
        display: inline;
        max- auto;
        padding: 0;
        margin: 0;
        overflow: visible;
        line-height: inherit;
        word-wrap: normal;
        background-color: initial;
        border: 0;
    }
    
    article .commit-tease-sha {
        display: inline-block;
        font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
        font-size: 90%;
        color: #444d56;
    }
    
    article .full-commit .btn-outline:not(:disabled):hover {
        color: #005cc5;
        border-color: #005cc5;
    }
    
    article .blob-wrapper {
        overflow-x: auto;
        overflow-y: hidden;
    }
    
    article .blob-wrapper-embedded {
        max-height: 240px;
        overflow-y: auto;
    }
    
    article .blob-num {
         1%;
        min- 50px;
        padding-right: 10px;
        padding-left: 10px;
        font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
        font-size: 12px;
        line-height: 20px;
        color: rgba(27, 31, 35, .3);
        text-align: right;
        white-space: nowrap;
        vertical-align: top;
        cursor: pointer;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    article .blob-num:hover {
        color: rgba(27, 31, 35, .6);
    }
    
    article .blob-num:before {
        content: attr(data-line-number);
    }
    
    article .blob-code {
        position: relative;
        padding-right: 10px;
        padding-left: 10px;
        line-height: 20px;
        vertical-align: top;
    }
    
    article .blob-code-inner {
        overflow: visible;
        font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
        font-size: 12px;
        color: #24292e;
        word-wrap: normal;
        white-space: pre;
    }
    
    article .pl-token.active,
    article .pl-token:hover {
        cursor: pointer;
        background: #ffea7f;
    }
    
    article .tab-size[data-tab-size="1"] {
        -moz-tab-size: 1;
        tab-size: 1;
    }
    
    article .tab-size[data-tab-size="2"] {
        -moz-tab-size: 2;
        tab-size: 2;
    }
    
    article .tab-size[data-tab-size="3"] {
        -moz-tab-size: 3;
        tab-size: 3;
    }
    
    article .tab-size[data-tab-size="4"] {
        -moz-tab-size: 4;
        tab-size: 4;
    }
    
    article .tab-size[data-tab-size="5"] {
        -moz-tab-size: 5;
        tab-size: 5;
    }
    
    article .tab-size[data-tab-size="6"] {
        -moz-tab-size: 6;
        tab-size: 6;
    }
    
    article .tab-size[data-tab-size="7"] {
        -moz-tab-size: 7;
        tab-size: 7;
    }
    
    article .tab-size[data-tab-size="8"] {
        -moz-tab-size: 8;
        tab-size: 8;
    }
    
    article .tab-size[data-tab-size="9"] {
        -moz-tab-size: 9;
        tab-size: 9;
    }
    
    article .tab-size[data-tab-size="10"] {
        -moz-tab-size: 10;
        tab-size: 10;
    }
    
    article .tab-size[data-tab-size="11"] {
        -moz-tab-size: 11;
        tab-size: 11;
    }
    
    article .tab-size[data-tab-size="12"] {
        -moz-tab-size: 12;
        tab-size: 12;
    }
    
    article .task-list-item {
        list-style-type: none;
    }
    
    article .task-list-item+.task-list-item {
        margin-top: 3px;
    }
    
    article .task-list-item input {
        margin: 0 .2em .25em -1.6em;
        vertical-align: middle;
    }
    

      

    四、新建markdown-block.vue

    <template>
      <div class="demo-block">
        <div class="demo-block-source">
          <slot name="source"></slot>
          <span
            class="demo-block-code-icon"
            v-if="!$slots.default"
            @click="showCode = !showCode"
            ><img
              alt="expand code"
              src="https://gw.alipayobjects.com/zos/rmsportal/wSAkBuJFbdxsosKKpqyq.svg"
              class="code-expand-icon-show"
          /></span>
        </div>
        <div class="demo-block-meta" v-if="$slots.default">
          <slot></slot>
          <span
            v-if="$slots.default"
            class="demo-block-code-icon"
            @click="showCode = !showCode"
            ><img
              alt="expand code"
              src="https://gw.alipayobjects.com/zos/rmsportal/wSAkBuJFbdxsosKKpqyq.svg"
              class="code-expand-icon-show"
          /></span>
        </div>
        <div class="demo-block-code" v-show="showCode">
          <slot name="highlight"></slot>
        </div>
      </div>
    </template>
    <script type="text/babel">
    import 'highlight.js/styles/color-brewer.css';  
    export default {
      data() {
        return {
          showCode: false,
        }
      },
    }
    </script>
    <style scoped>
    @import '../../assets/css/github-markdown.css';
    .demo-block {
      border: 1px solid #ebedf0;
      border-radius: 2px;
      display: inline-block;
       100%;
      position: relative;
      margin: 0 0 16px;
      -webkit-transition: all 0.2s;
      transition: all 0.2s;
      border-radius: 2px;
    }
    .demo-block p {
      padding: 0;
      margin: 0;
    }
    .demo-block .demo-block-code-icon {
      position: absolute;
      right: 16px;
      bottom: 14px;
      cursor: pointer;
       18px;
      height: 18px;
      line-height: 18px;
      text-align: center;
    }
    .demo-block .demo-block-code-icon img {
      -webkit-transition: all 0.4s;
      transition: all 0.4s;
      -webkit-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      user-select: none;
      position: absolute;
      left: 0;
      top: 0;
      margin: 0;
      max- 100%;
       100%;
      vertical-align: baseline;
      -webkit-box-shadow: none;
      box-shadow: none;
    }
    .demo-block .demo-block-source {
      border-bottom: 1px solid #ebedf0;
      padding: 20px 24px 20px;
      color: #444;
      position: relative;
      margin-bottom: -1px;
    }
    .demo-block .demo-block-meta {
      position: relative;
      padding: 12px 50px 12px 20px;
      border-radius: 0 0 2px 2px;
      -webkit-transition: background-color 0.4s;
      transition: background-color 0.4s;
       100%;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      font-size: 14px;
      color: #444;
      font-size: 14px;
      line-height: 2;
      border-radius: 0;
      border-bottom: 1px dashed #ebedf0;
      margin-bottom: -1px;
    }
    .demo-block .demo-block-meta code {
      color: #444;
      background-color: #e6effb;
      margin: 0 4px;
      display: inline-block;
      padding: 3px 7px;
      border-radius: 3px;
      height: 18px;
      line-height: 18px;
      font-family: Menlo, Monaco, Consolas, Courier, monospace;
      font-size: 14px;
    }
    .demo-block .demo-block-code {
      background-color: #f7f7f7;
      font-size: 0;
    }
    .demo-block .demo-block-code code {
      background-color: #f7f7f7;
      font-family: Consolas, Menlo, Courier, monospace;
      border: none;
      display: block;
      font-size: 14px;
      padding: 16px 32px;
    }
    .demo-block .demo-block-code pre {
      margin: 0;
      padding: 0;
    }
    .sh-checkbox {
      color: #444;
      font-weight: 500;
      font-size: 14px;
      position: relative;
      cursor: pointer;
      display: inline-block;
      white-space: nowrap;
      user-select: none;
    }
    </style>
    

    五、在main.js中注册组件

    import DemoBlock from '@/components/public/markdown-block.vue'
    Vue.component('demo-block', DemoBlock)
    

      

    六、在根目录下新建 ui/docs/tab-search.md 文件

    ## Button 按钮
    
    常用的操作按钮
    
    ### 基础用法 
    
    按钮的基础用法
    
    :::demo 通过`type`、`width`属性设置不同类型的按钮
    
    ```html
    <template>
        <div>
            <el-button>默认按钮</el-button>
            <el-button type="success">成功按钮</el-button>
            <el-button type="warning">警告按钮</el-button>
            <el-button type="danger">危险按钮</el-button>
        </div>
        <div>
            <el-button width="100px">默认按钮</el-button>
            <el-button type="success" width="100px">成功按钮</el-button>
            <el-button type="warning" width="100px">警告按钮</el-button>
            <el-button type="danger" width="100px">危险按钮</el-button>
        </div>
    </template>
    \```  (去除这个斜杠)
    
    :::
    
    ### Attributes
    | 参数      | 说明    | 类型      | 可选值       | 默认值   |
    |--------|--------   |---------- |-------------  |-------- |
    | type   | 类型      | string    |   success / warning / danger / |—    |
    | name   | name属性  | string    | — | —   |
    | id     | id属性    | string    | — | —   |
    | width  | 按钮宽度   | string    | — | 100%   |
    

      

    七、配置路由

          {
            path: '/search',
            name: 'search',
            meta: {
              title: '搜索',
              icon: 'home1',
              keepAlive: true,
            },
            component: () => import('@/ui/docs/tab-search.md'),
          },
    

      

    八、访问页面查看效果

    article .octicon {
        displayinline-block;
        fillcurrentColor;
        vertical-aligntext-bottom;
    }

    article .anchor {
        floatleft;
        line-height1;
        margin-left-20px;
        padding-right4px;
    }

    article .anchor:focus {
        outlinenone;
    }

    article h1 .octicon-link,
    article h2 .octicon-link,
    article h3 .octicon-link,
    article h4 .octicon-link,
    article h5 .octicon-link,
    article h6 .octicon-link {
        color#1b1f23;
        vertical-alignmiddle;
        visibilityhidden;
    }

    article h1:hover .anchor,
    article h2:hover .anchor,
    article h3:hover .anchor,
    article h4:hover .anchor,
    article h5:hover .anchor,
    article h6:hover .anchor {
        text-decorationnone;
    }

    article h1:hover .anchor .octicon-link,
    article h2:hover .anchor .octicon-link,
    article h3:hover .anchor .octicon-link,
    article h4:hover .anchor .octicon-link,
    article h5:hover .anchor .octicon-link,
    article h6:hover .anchor .octicon-link {
        visibilityvisible;
    }

    article h1:hover .anchor .octicon-link:before,
    article h2:hover .anchor .octicon-link:before,
    article h3:hover .anchor .octicon-link:before,
    article h4:hover .anchor .octicon-link:before,
    article h5:hover .anchor .octicon-link:before,
    article h6:hover .anchor .octicon-link:before {
        width16px;
        height16px;
        content' ';
        displayinline-block;
        background-imageurl("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' version='1.1' width='16' height='16' aria-hidden='true'%3E%3Cpath fill-rule='evenodd' d='M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z'%3E%3C/path%3E%3C/svg%3E");
    }

    article {
        -ms-text-size-adjust100%;
        -webkit-text-size-adjust100%;
        line-height1.5;
        color#24292e;
        font-family-apple-system, BlinkMacSystemFont, Segoe UI, HelveticaArialsans-serif, Apple Color Emoji, Segoe UI Emoji;
        font-size16px;
        line-height1.5;
        word-wrapbreak-word;
    }

    article details {
        displayblock;
    }

    article summary {
        displaylist-item;
    }

    article a {
        background-colorinitial;
    }

    article a:active,
    article a:hover {
        outline-width0;
    }

    article strong {
        font-weightinherit;
        font-weightbolder;
    }

    article h1 {
        font-size2em;
        margin.67em 0;
    }

    article img {
        border-stylenone;
    }

    article code,
    article kbd,
    article pre {
        font-familymonospacemonospace;
        font-size1em;
    }

    article hr {
        box-sizinginitial;
        height0;
        overflowvisible;
    }

    article input {
        fontinherit;
        margin0;
    }

    article input {
        overflowvisible;
    }

    article [type=checkbox] {
        box-sizingborder-box;
        padding0;
    }

    article * {
        box-sizingborder-box;
    }

    article input {
        font-familyinherit;
        font-sizeinherit;
        line-heightinherit;
    }

    article a {
        color#0366d6;
        text-decorationnone;
    }

    article a:hover {
        text-decorationunderline;
    }

    article strong {
        font-weight600;
    }

    article hr {
        height0;
        margin15px 0;
        overflowhidden;
        backgroundtransparent;
        border0;
        border-bottom1px solid #dfe2e5;
    }

    article hr:after,
    article hr:before {
        displaytable;
        content"";
    }

    article hr:after {
        clearboth;
    }

    article table {
        border-spacing0;
        border-collapsecollapse;
    }

    article td,
    article th {
        padding0;
    }

    article details summary {
        cursorpointer;
    }

    article kbd {
        displayinline-block;
        padding3px 5px;
        font11px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
        line-height10px;
        color#444d56;
        vertical-alignmiddle;
        background-color#fafbfc;
        border1px solid #d1d5da;
        border-radius3px;
        box-shadowinset 0 -1px 0 #d1d5da;
    }

    article h1,
    article h2,
    article h3,
    article h4,
    article h5,
    article h6 {
        margin-top0;
        margin-bottom0;
    }

    article h1 {
        font-size32px;
    }

    article h1,
    article h2 {
        font-weight600;
    }

    article h2 {
        font-size24px;
    }

    article h3 {
        font-size20px;
    }

    article h3,
    article h4 {
        font-weight600;
    }

    article h4 {
        font-size16px;
    }

    article h5 {
        font-size14px;
    }

    article h5,
    article h6 {
        font-weight600;
    }

    article h6 {
        font-size12px;
    }

    article p {
        margin-top0;
        margin-bottom10px;
    }

    article blockquote {
        margin0;
    }

    article ol,
    article ul {
        padding-left0;
        margin-top0;
        margin-bottom0;
    }

    article ol ol,
    article ul ol {
        list-style-typelower-roman;
    }

    article ol ol ol,
    article ol ul ol,
    article ul ol ol,
    article ul ul ol {
        list-style-typelower-alpha;
    }

    article dd {
        margin-left0;
    }

    article code,
    article pre {
        font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
        font-size12px;
    }

    article pre {
        margin-top0;
        margin-bottom0;
    }

    article input::-webkit-inner-spin-button,
    article input::-webkit-outer-spin-button {
        margin0;
        -webkit-appearancenone;
        appearancenone;
    }

    article :checked+.radio-label {
        positionrelative;
        z-index1;
        border-color#0366d6;
    }

    article .border {
        border1px solid #e1e4e8 !important;
    }

    article .border-0 {
        border0 !important;
    }

    article .border-bottom {
        border-bottom1px solid #e1e4e8 !important;
    }

    article .rounded-1 {
        border-radius3px !important;
    }

    article .bg-white {
        background-color#fff !important;
    }

    article .bg-gray-light {
        background-color#fafbfc !important;
    }

    article .text-gray-light {
        color#6a737d !important;
    }

    article .mb-0 {
        margin-bottom0 !important;
    }

    article .my-2 {
        margin-top8px !important;
        margin-bottom8px !important;
    }

    article .pl-0 {
        padding-left0 !important;
    }

    article .py-0 {
        padding-top0 !important;
        padding-bottom0 !important;
    }

    article .pl-1 {
        padding-left4px !important;
    }

    article .pl-2 {
        padding-left8px !important;
    }

    article .py-2 {
        padding-top8px !important;
        padding-bottom8px !important;
    }

    article .pl-3,
    article .px-3 {
        padding-left16px !important;
    }

    article .px-3 {
        padding-right16px !important;
    }

    article .pl-4 {
        padding-left24px !important;
    }

    article .pl-5 {
        padding-left32px !important;
    }

    article .pl-6 {
        padding-left40px !important;
    }

    article .f6 {
        font-size12px !important;
    }

    article .lh-condensed {
        line-height1.25 !important;
    }

    article .text-bold {
        font-weight600 !important;
    }

    article .pl-c {
        color#6a737d;
    }

    article .pl-c1,
    article .pl-s .pl-v {
        color#005cc5;
    }

    article .pl-e,
    article .pl-en {
        color#6f42c1;
    }

    article .pl-s .pl-s1,
    article .pl-smi {
        color#24292e;
    }

    article .pl-ent {
        color#22863a;
    }

    article .pl-k {
        color#d73a49;
    }

    article .pl-pds,
    article .pl-s,
    article .pl-s .pl-pse .pl-s1,
    article .pl-sr,
    article .pl-sr .pl-cce,
    article .pl-sr .pl-sra,
    article .pl-sr .pl-sre {
        color#032f62;
    }

    article .pl-smw,
    article .pl-v {
        color#e36209;
    }

    article .pl-bu {
        color#b31d28;
    }

    article .pl-ii {
        color#fafbfc;
        background-color#b31d28;
    }

    article .pl-c2 {
        color#fafbfc;
        background-color#d73a49;
    }

    article .pl-c2:before {
        content"^M";
    }

    article .pl-sr .pl-cce {
        font-weight700;
        color#22863a;
    }

    article .pl-ml {
        color#735c0f;
    }

    article .pl-mh,
    article .pl-mh .pl-en,
    article .pl-ms {
        font-weight700;
        color#005cc5;
    }

    article .pl-mi {
        font-styleitalic;
        color#24292e;
    }

    article .pl-mb {
        font-weight700;
        color#24292e;
    }

    article .pl-md {
        color#b31d28;
        background-color#ffeef0;
    }

    article .pl-mi1 {
        color#22863a;
        background-color#f0fff4;
    }

    article .pl-mc {
        color#e36209;
        background-color#ffebda;
    }

    article .pl-mi2 {
        color#f6f8fa;
        background-color#005cc5;
    }

    article .pl-mdr {
        font-weight700;
        color#6f42c1;
    }

    article .pl-ba {
        color#586069;
    }

    article .pl-sg {
        color#959da5;
    }

    article .pl-corl {
        text-decorationunderline;
        color#032f62;
    }

    article .mb-0 {
        margin-bottom0 !important;
    }

    article .my-2 {
        margin-bottom8px !important;
    }

    article .my-2 {
        margin-top8px !important;
    }

    article .pl-0 {
        padding-left0 !important;
    }

    article .py-0 {
        padding-top0 !important;
        padding-bottom0 !important;
    }

    article .pl-1 {
        padding-left4px !important;
    }

    article .pl-2 {
        padding-left8px !important;
    }

    article .py-2 {
        padding-top8px !important;
        padding-bottom8px !important;
    }

    article .pl-3 {
        padding-left16px !important;
    }

    article .pl-4 {
        padding-left24px !important;
    }

    article .pl-5 {
        padding-left32px !important;
    }

    article .pl-6 {
        padding-left40px !important;
    }

    article .pl-7 {
        padding-left48px !important;
    }

    article .pl-8 {
        padding-left64px !important;
    }

    article .pl-9 {
        padding-left80px !important;
    }

    article .pl-10 {
        padding-left96px !important;
    }

    article .pl-11 {
        padding-left112px !important;
    }

    article .pl-12 {
        padding-left128px !important;
    }

    article hr {
        border-bottom-color#eee;
    }

    article kbd {
        displayinline-block;
        padding3px 5px;
        font11px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
        line-height10px;
        color#444d56;
        vertical-alignmiddle;
        background-color#fafbfc;
        border1px solid #d1d5da;
        border-radius3px;
        box-shadowinset 0 -1px 0 #d1d5da;
    }

    article:after,
    article:before {
        displaytable;
        content"";
    }

    article:after {
        clearboth;
    }

    article>:first-child {
        margin-top0 !important;
    }

    article>:last-child {
        margin-bottom0 !important;
    }

    article a:not([href]) {
        colorinherit;
        text-decorationnone;
    }

    article blockquote,
    article details,
    article dl,
    article ol,
    article p,
    article pre,
    article table,
    article ul {
        margin-top0;
        margin-bottom16px;
    }

    article hr {
        height.25em;
        padding0;
        margin24px 0;
        background-color#e1e4e8;
        border0;
    }

    article blockquote {
        padding0 1em;
        color#6a737d;
        border-left.25em solid #dfe2e5;
    }

    article blockquote>:first-child {
        margin-top0;
    }

    article blockquote>:last-child {
        margin-bottom0;
    }

    article h1,
    article h2,
    article h3,
    article h4,
    article h5,
    article h6 {
        margin-top24px;
        margin-bottom16px;
        font-weight600;
        line-height1.25;
    }

    article h1 {
        font-size2em;
    }

    article h1,
    article h2 {
        padding-bottom.3em;
        border-bottom1px solid #eaecef;
    }

    article h2 {
        font-size1.5em;
    }

    article h3 {
        font-size1.25em;
    }

    article h4 {
        font-size1em;
    }

    article h5 {
        font-size.875em;
    }

    article h6 {
        font-size.85em;
        color#6a737d;
    }

    article ol,
    article ul {
        padding-left2em;
    }

    article ol ol,
    article ol ul,
    article ul ol,
    article ul ul {
        margin-top0;
        margin-bottom0;
    }

    article li {
        word-wrapbreak-all;
    }

    article li>p {
        margin-top16px;
    }

    article li+li {
        margin-top.25em;
    }

    article dl {
        padding0;
    }

    article dl dt {
        padding0;
        margin-top16px;
        font-size1em;
        font-styleitalic;
        font-weight600;
    }

    article dl dd {
        padding0 16px;
        margin-bottom16px;
    }

    article table {
        displayblock;
        width100%;
        overflowauto;
    }

    article table th {
        font-weight600;
    }

    article table td,
    article table th {
        padding6px 13px;
        border1px solid #dfe2e5;
    }

    article table tr {
        background-color#fff;
        border-top1px solid #c6cbd1;
    }

    article table tr:nth-child(2n) {
        background-color#f6f8fa;
    }

    article img {
        max-width100%;
        box-sizinginitial;
        background-color#fff;
    }

    article img[align=right] {
        padding-left20px;
    }

    article img[align=left] {
        padding-right20px;
    }

    article code {
        padding.2em .4em;
        margin0;
        font-size85%;
        background-colorrgba(273135.05);
        border-radius3px;
    }

    article pre {
        word-wrapnormal;
    }

    article pre>code {
        padding0;
        margin0;
        font-size100%;
        word-breaknormal;
        white-spacepre;
        backgroundtransparent;
        border0;
    }

    article .highlight {
        margin-bottom16px;
    }

    article .highlight pre {
        margin-bottom0;
        word-breaknormal;
    }

    article .highlight pre,
    article pre {
        padding16px;
        overflowauto;
        font-size85%;
        line-height1.45;
        background-color#f6f8fa;
        border-radius3px;
    }

    article pre code {
        displayinline;
        max-widthauto;
        padding0;
        margin0;
        overflowvisible;
        line-heightinherit;
        word-wrapnormal;
        background-colorinitial;
        border0;
    }

    article .commit-tease-sha {
        displayinline-block;
        font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
        font-size90%;
        color#444d56;
    }

    article .full-commit .btn-outline:not(:disabled):hover {
        color#005cc5;
        border-color#005cc5;
    }

    article .blob-wrapper {
        overflow-xauto;
        overflow-yhidden;
    }

    article .blob-wrapper-embedded {
        max-height240px;
        overflow-yauto;
    }

    article .blob-num {
        width1%;
        min-width50px;
        padding-right10px;
        padding-left10px;
        font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
        font-size12px;
        line-height20px;
        colorrgba(273135.3);
        text-alignright;
        white-spacenowrap;
        vertical-aligntop;
        cursorpointer;
        -webkit-user-selectnone;
        -moz-user-selectnone;
        -ms-user-selectnone;
        user-selectnone;
    }

    article .blob-num:hover {
        colorrgba(273135.6);
    }

    article .blob-num:before {
        contentattr(data-line-number);
    }

    article .blob-code {
        positionrelative;
        padding-right10px;
        padding-left10px;
        line-height20px;
        vertical-aligntop;
    }

    article .blob-code-inner {
        overflowvisible;
        font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
        font-size12px;
        color#24292e;
        word-wrapnormal;
        white-spacepre;
    }

    article .pl-token.active,
    article .pl-token:hover {
        cursorpointer;
        background#ffea7f;
    }

    article .tab-size[data-tab-size="1"] {
        -moz-tab-size1;
        tab-size1;
    }

    article .tab-size[data-tab-size="2"] {
        -moz-tab-size2;
        tab-size2;
    }

    article .tab-size[data-tab-size="3"] {
        -moz-tab-size3;
        tab-size3;
    }

    article .tab-size[data-tab-size="4"] {
        -moz-tab-size4;
        tab-size4;
    }

    article .tab-size[data-tab-size="5"] {
        -moz-tab-size5;
        tab-size5;
    }

    article .tab-size[data-tab-size="6"] {
        -moz-tab-size6;
        tab-size6;
    }

    article .tab-size[data-tab-size="7"] {
        -moz-tab-size7;
        tab-size7;
    }

    article .tab-size[data-tab-size="8"] {
        -moz-tab-size8;
        tab-size8;
    }

    article .tab-size[data-tab-size="9"] {
        -moz-tab-size9;
        tab-size9;
    }

    article .tab-size[data-tab-size="10"] {
        -moz-tab-size10;
        tab-size10;
    }

    article .tab-size[data-tab-size="11"] {
        -moz-tab-size11;
        tab-size11;
    }

    article .tab-size[data-tab-size="12"] {
        -moz-tab-size12;
        tab-size12;
    }

    article .task-list-item {
        list-style-typenone;
    }

    article .task-list-item+.task-list-item {
        margin-top3px;
    }

    article .task-list-item input {
        margin0 .2em .25em -1.6em;
        vertical-alignmiddle;
    }
  • 相关阅读:
    ODI Scenario 场景
    数据库权限管理
    Oracle KEEP 分析函数
    Oracle数据仓库套件
    复杂透视表的SQL生成方法
    DW/BI领域的自动化调度方案
    用户画像
    PCP
    理赔系统报表及表模型
    maltab 关于输入输出以及自定义函数的问题
  • 原文地址:https://www.cnblogs.com/maxiansheng/p/13941619.html
Copyright © 2020-2023  润新知