亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Vuepress使用vue組件實(shí)現(xiàn)頁面改造

 更新時(shí)間:2022年07月05日 10:42:11   作者:Gaby  
這篇文章主要為大家介紹了Vuepress使用vue組件實(shí)現(xiàn)頁面改造示例過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

引言

只是單純的用 vuepress 寫個(gè) markdown 文檔,的確會(huì)處處受限,滿足不了定制化的樣式和功能,有時(shí)只是簡(jiǎn)單的修改下某個(gè)頁面,或者做些組件演示的內(nèi)容,而不是開發(fā)一整套主題。所以研究下如何在項(xiàng)目中使用 vue 組件還有非常有必要的,畢竟也沒那么難。

前置環(huán)境

  • node 環(huán)境 node v16.13.0
  • VuePress 版本 VuePress v2.0.0-beta.48

每個(gè)版本的使用方式還是有些差異的,尤其是 1.x2.x,所以在閱讀的時(shí)候盡量與自己所用的版本對(duì)比下,避免不必要的試錯(cuò)。

使用 vue 組件

安裝插件

Vuepress2.x 中需要安裝 @vuepress/plugin-register-components 插件并做好配置,而在Vuepress1.0中,md 文件能自動(dòng)識(shí)別導(dǎo)出的.vue文件。

yarn add @vuepress/plugin-register-components@next
// 或者
npm i -D @vuepress/plugin-register-components@next

配置插件

config.js中配置修改如下:

? 官方配置項(xiàng)文檔

const { registerComponentsPlugin } = require('@vuepress/plugin-register-components')
module.exports = {
  plugins: [
    registerComponentsPlugin({
      // 配置項(xiàng)
    }),
  ],
}

我本地的配置文件的部分內(nèi)容:

const path = require("path");
const { defaultTheme } = require('vuepress');
const { docsearchPlugin } = require('@vuepress/plugin-docsearch')
// ======================引入插件====================================
const { registerComponentsPlugin } = require('@vuepress/plugin-register-components')
// ======================引入插件 End================================
const navbar = require('./navbar');
const sidebar = require('./sidebar');
module.exports = {
  base: '/',
  lang: 'zh-CN',
  title: '前端技術(shù)棧',
  description: '前端白皮書',
  head: [
    ['link', { rel: 'manifest', href: '/manifest.webmanifest' }],
    ['meta', { name: 'theme-color', content: '#3eaf7c' }]
  ],
  alias: {
    '@pub': path.resolve(__dirname, './public'),
  },
  markdown: {
    importCode: {
      handleImportPath: (str) =>
          str.replace(/^@src/, path.resolve(__dirname, 'src')),
    },
    extractTitle: true
  },
  // ======================配置插件====================================
  plugins: [
    registerComponentsPlugin({
      // 配置項(xiàng)
      componentsDir: path.resolve(__dirname, './components')
    })
  ],
  // ======================配置插件 End=================================
  theme: defaultTheme({
    // URL
    logo: 'https://vuejs.org/images/logo.png',
    // 頂部導(dǎo)航
    navbar: navbar,
    // 側(cè)邊欄
    sidebar: sidebar,
    sidebarDepth: 2, // e'b將同時(shí)提取markdown中h2 和 h3 標(biāo)題,顯示在側(cè)邊欄上。
    lastUpdated: true // 文檔更新時(shí)間:每個(gè)文件git最后提交的時(shí)間
  })
}

創(chuàng)建 vue 組件

.vuepress文件夾中新建components文件夾,里面存放vue組件,文件結(jié)構(gòu)如下:

├─.vuepress
│  └─ components
│  │  └─ Card.vue
│  └─ config
│  │  └─ navbar.js
│  │  └─ sidebar.js
│  └─ public
│  │  └─ images
│  └─ config.js

至此md文件就能無需引入即可自動(dòng)識(shí)別.vuepress/components/下所有的vue組件了。繼續(xù)完成下面的步驟,就可以看到項(xiàng)目中使用的效果。

Card.vue 文件內(nèi)容如下,這個(gè)組件個(gè)人可以因需而定,這里只做個(gè)參照,和后面的效果對(duì)應(yīng)上。key這里沒有設(shè)置業(yè)務(wù) ID 暫且使用 k來代替。

<template>
  <div class="g-card-link">
    <div v-for="(item,k) in value" class="g-card-item" :key="k">
      <a :href="item.link" rel="external nofollow"  target="_blank" :title="item.title">{{item.title}}</a>
    </div>
  </div>
</template>
<script setup>
import { ref, defineProps } from 'vue';
const props = defineProps({
  defaultValue:String
})
const value = ref(props.defaultValue);
</script>
<style lang="scss">
button {background-color: #4e6ef2}
.g-card-link {
  display: flex;
  flex-wrap: wrap;
  gap:10px;
  text-align: center;
  line-height: 38px;
  .g-card-item {
    background: blue;
    width: 113px;
    max-width: 138px;
    height: 38px;
    cursor: pointer;
    overflow: hidden;
  }
  .g-card-item:nth-of-type(2n) {
    background: rgba(44,104,255,.1);
  }
  .g-card-item:nth-of-type(2n+1) {
    background: rgba(56, 203, 137, .1);
  }
}
</style>

使用 vue 組件

docs/docs/README.md 文件直接引入Card.vue,當(dāng)然文檔路徑你可以自由選擇。這里我們給組件傳了數(shù)據(jù),如果沒有數(shù)據(jù)交互會(huì)更簡(jiǎn)單,直接引用就行了。

---
data: 2022-06-14
lang: zh-CN
title: Docs 常用文檔
description: 收集常用的文檔
---
# Docs
收集精編常用的文檔...
<div v-for="(item,k) in linkList">
    <h3>{{item.title}}</h3>
    <div>
        <card :defaultValue="item.children"/>
    </div>
</div>
<script setup>
import { ref } from 'vue';
const linkList = ref([]);
linkList.value = [
    {
        title: 'React UI 組件庫',
        children: [
            {
                title: 'Ant Design',
                link: 'https://ant.design/docs/react/introduce-cn'
            },{
                title: 'Bootstrap',
                link: 'https://react-bootstrap.github.io/getting-started/introduction'
            },{
                title: 'Material UI',
                link: 'https://mui.com/material-ui/getting-started/overview/'
            }
        ]
    },{
        title: 'Vue UI 組件庫',
        children: [
            {
                title: 'Element',
                link: 'https://element.eleme.io/#/zh-CN/component/installation'
            },{
                title: 'Element Plus',
                link: 'https://element-plus.org/zh-CN/component/button.html'
            },{
                title: 'Vant',
                link: 'https://youzan.github.io/vant/#/zh-CN'
            },{
                title: 'View Design',
                link: 'https://www.iviewui.com/view-ui-plus/guide/introduce'
            }
        ]
    },
    {
        title: '動(dòng)畫庫',
        children: [
            {
                title: 'Animate.css',
                link: 'https://animate.style/'
            }
        ]
    }
]
</script>

至此組件已經(jīng)引入到頁面中可,我們來看看效果 ? 傳送門

以上就是Vuepress使用vue組件實(shí)現(xiàn)頁面改造的詳細(xì)內(nèi)容,更多關(guān)于Vuepress vue組件頁面改造的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論