最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

html中引入Vue.js的cdn實現(xiàn)簡單的文檔單頁

 更新時間:2023年08月06日 15:57:12   作者:TANKING  
這篇文章主要為大家介紹了html中引入Vue.js的cdn實現(xiàn)簡單的文檔單頁示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

摘要

平時要編寫一篇技術(shù)文檔、開發(fā)文檔、博客,都有很多的選擇。例如Vuepress,showDoc,甚至使用騰訊文檔等這一類的文檔工具,都可以寫。

html引入vue.js

我現(xiàn)在使用html引入vue.js的方式編寫一個單頁文檔網(wǎng)頁。

<!DOCTYPE html>
<html lang="en">
<head>
  <title>單頁文檔</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="vue.js"></script>
  <script src="vue-router.min.js"></script>
  <style>
    *{
      padding: 0;
      margin: 0;
      font-family: font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
    }
    body {
      margin: 0;
      font-family: Arial, sans-serif;
      background: #fff;
    }
    .header{
      width: 100%;
      height: 55px;
      border-bottom: 1px solid #eee;
      margin: 0 auto;
      background: #fff;
      position: fixed;
      top: 0;
    }
    .container {
      width: 70%;
      margin: 100px auto 0;
      display: flex;
    }
    .sidebar {
      width: 250px;
      flex: 1;
      border-right: 1px solid #eee;
      position: fixed;
      height: 100%;
      overflow-y: auto;
    }
    .menu-item {
      cursor: pointer;
      padding: 12px 20px;
      font-size: 17px;
    }
    .sub-menu-item {
      cursor: pointer;
      padding: 5px 0 5px 40px;
      font-size: 15px;
    }
    .content {
      flex: 2;
      padding: 30px;
      margin-left: 300px;
      background: #F6F8FA;
    }
    .content h1 {
        font-size: 2.5rem;
        font-weight: 500;
        margin: 0 0 12px 0;
        border-bottom: 1px solid #e9e9e9;
        padding-bottom: 10px;
    }
    .content h2 {
        font-size: 1.5rem;
        font-weight: 500;
        margin: 0 0 12px 0;
        border-bottom: 1px solid #e9e9e9;
        padding-bottom: 10px;
    }
    .content h3 {
        font-size: 1.17rem;
        font-weight: 500;
        margin: 0 0 12px 0;
        border-bottom: 1px solid #e9e9e9;
        padding-bottom: 10px;
    }
    .content h4 {
        font-size: 1.33rem;
        font-weight: 500;
        margin: 0 0 12px 0;
        border-bottom: 1px solid #e9e9e9;
        padding-bottom: 10px;
    }
    .content h5 {
        font-size: 0.83rem;
        font-weight: 500;
        margin: 0 0 12px 0;
        border-bottom: 1px solid #e9e9e9;
        padding-bottom: 10px;
    }
    .content p{
      font-size: 1rem;
      color: #2C3E50;
      line-height: 27px;
    }
    .content code{
      color: #476582;
      padding: 0.25rem 0.5rem;
      margin: 0;
      font-size: 0.9em;
      background-color: rgba(27,31,35,.05);
      border-radius: 3px;
    }
    /* 滑動效果 */
    .slide-fade-enter-active {
      transition: all 0.3s ease;
    }
    .slide-fade-leave-active {
      transition: all 0.3s cubic-bezier(1.0, 0.5, 0.8, 1.0);
    }
    .slide-fade-enter, .slide-fade-leave-to {
      transform: translateX(10px);
      opacity: 0;
    }
    /* 漸變淡入淡出 */
    .fade-enter-active, .fade-leave-active {
      transition: opacity 0.5s;
    }
    .fade-enter, .fade-leave-to {
      opacity: 0;
    }
    /*導(dǎo)航選中的樣式*/
    .selectedItem {
      color: #42B983;
    }
  </style>
</head>
<body>
  <div id="app">
    <!-- 頂部頁頭 -->
    <div class="header"></div>
    <div class="container">
      <!-- 導(dǎo)航容器 -->
      <div class="sidebar">
        <ul>
          <li v-for="item in menuItems" :key="item.id">
            <div class="menu-item" @click="handleMenuItemClick(item)" :class="{ 'selectedItem': selectedMenuItemId === item.id }">
              {{ item.name }}
            </div>
            <ul v-if="item.subItems">
              <li class="sub-menu-item" v-for="subItem in item.subItems" :key="subItem.id" @click="changeRoute(subItem.id)" :class="{ 'selectedItem': selectedSubMenuItemId === subItem.id }">
                {{ subItem.name }}
              </li>
            </ul>
          </li>
        </ul>
      </div>
      <!-- 內(nèi)容容器 -->
      <div class="content">
        <!-- 過渡動畫 -->
        <transition name="slide-fade" mode="out-in">
          <router-view :contents="contents" :key="$route.fullPath"></router-view>
        </transition>
      </div>
    </div>
  </div>
  <script>
    // 注冊全局的組件
    Vue.component('content-component', {
      props: ['content'],
      template: '<div v-html="content"></div>'
    });
    // 自定義Vue組件,在路由切換時展示不同內(nèi)容的頁面
    const ContentPage = {
      props: ['contents'],
      template: '<content-component :content="contents[selectedContent]"></content-component>',
      computed: {
        selectedContent() {
          return this.$route.params.contentId;
        }
      }
    };
    // 定義Vue Router的路由配置
    const routes = [
      { path: '/', component: { template: '<div>Welcome to the app</div>' } },
      { path: '/:contentId', component: ContentPage, props: true }
    ];
    // 創(chuàng)建Vue Router實例
    const router = new VueRouter({
      routes
    });
    // 創(chuàng)建Vue實例
    new Vue({
      el: '#app',
      router,
      data: {
        menuItems: [
          { id: 'content-1', name: 'Vue 核心基礎(chǔ)知識梳理', subItems: [
            { id: 'sub-content-1', name: 'Vue 實例(應(yīng)用)相關(guān)' },
            { id: 'sub-content-2', name: 'Vue 樣式相關(guān)' },
            { id: 'sub-content-3', name: 'Vue 常見指令' }
          ] },
          { id: 'content-2', name: 'Vue 高級知識梳理', subItems: [
            { id: 'sub-content-666', name: 'Vue 的設(shè)計模式' },
            { id: 'sub-content-777', name: 'Vue 生命周期函數(shù)' }
          ] }
        ],
        contents: {
          'sub-content-1': '<h1>Vue 實例(應(yīng)用)相關(guān)</h1><p>Vue.createApp() 創(chuàng)建 vue 實例(應(yīng)用),參數(shù)可以決定根組件如何渲染!</p>',
          'sub-content-2': '<h2>Vue 樣式相關(guān)</h2><p>v-bind:class 的簡寫形式,為元素綁定動態(tài)類名。</p>',
          'sub-content-3': '<h1>Vue 常見指令</h1><p>綁定事件</p><p>① “v-on:”可以簡寫成@</p><p>② 可以使用“@[變量名]”,綁定動態(tài)事件。即,具體綁定哪個事件,由“變量名”決定</p><p>③ 事件處理函數(shù)中,可以使用事件對象 event</p><p>④ 事件處理函數(shù)中,如果想傳遞多個參數(shù),可以使用$event 指代事件對象</p>',
          'sub-content-666': '<h1>mvvm設(shè)計模式</h1><p>m 代表 model,指代數(shù)據(jù)</p><p>v 代表 view,指代視圖</p><p>vm 代表 viewModel,指代視圖數(shù)據(jù)連接層</p>',
          'sub-content-777': '<h1>Vue 生命周期函數(shù)</h1><p>beforeCreate(){}:在實例生成之前,會自動執(zhí)行該函數(shù)</p><p>beforeCreate(){}:在實例生成之前,會自動執(zhí)行該函數(shù)</p><p>created(){}:在實例生成之后,會自動執(zhí)行該函數(shù)</p><p>beforeMount(){}:在組件內(nèi)容被渲染到頁面之前,會自動執(zhí)行該函數(shù)</p><p>mounted(){}:組件內(nèi)容被渲染到頁面后,會自動執(zhí)行該函數(shù)</p><p>beforeUpdate(){}:當 data 中的數(shù)據(jù)發(fā)生變化時會自動執(zhí)行該函數(shù)</p><p>updated(){}:當 data 中的數(shù)據(jù)發(fā)生變化,同時頁面完成更新后,會自動執(zhí)行的函數(shù)</p><p>bbeforeUnmount(){} :當 <code>Vue</code> 應(yīng)用失效時,會自動執(zhí)行該函數(shù)</p><p>unmounted(){}:當 Vue 應(yīng)用失效后,同時 dom 完全銷毀之后,自動執(zhí)行的函數(shù)</p>'
        },
        selectedMenuItemId: null,
        selectedSubMenuItemId: null,
      },
      methods: {
        changeRoute(contentId) {
          if (this.$route.params.contentId !== contentId) {
            this.$router.push('/' + contentId);
            this.selectedSubMenuItemId = contentId; // 設(shè)置當前選擇的二級導(dǎo)航
            this.selectedMenuItemId = null; // 清空所選的一級導(dǎo)航
          }
        },
        handleMenuItemClick(menuItem) {
          if (menuItem.subItems) {
            menuItem.isExpanded = !menuItem.isExpanded;
            this.selectedMenuItemId = null; // 清空所選的一級導(dǎo)航
          } else {
            this.changeRoute(menuItem.id);
            this.selectedMenuItemId = menuItem.id;  // 設(shè)置當前選擇的一級導(dǎo)航
          }
        },
      }
    });
  </script>
</body>
</html>

同樣的,這個單頁文檔也是一個半成品,你需要引入vue.js的cdn、vue-router.min.js的cdn、以及axios.min.js的cdn,我這里是直接下載到本地了,因為比較快。

獲取數(shù)據(jù)并輸出json來渲染文檔

通過Json來配置左側(cè)的導(dǎo)航和右側(cè)的內(nèi)容

這里還沒有做請求接口獲取數(shù)據(jù),后期可以增加一個接口請求,獲取數(shù)據(jù)并輸出json來渲染文檔。

以上代碼是本地版,如需包含編輯器,數(shù)據(jù)庫后端等的可以咨詢我。

demo http://demo.likeyunba.com/vue-doc-spa/#/

同樣的,這就是一個Vue應(yīng)用,只不過沒有通過工程化構(gòu)建工具去做,而是引入cdn來使用Vue,也有自定義組件、路由管理、transition過渡動畫等相關(guān)的配置。

以上就是html中引入Vue.js的cdn實現(xiàn)簡單的文檔單頁的詳細內(nèi)容,更多關(guān)于html引入Vue.js cdn文檔單頁的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • el-date-picker日期選擇限制范圍的實例代碼

    el-date-picker日期選擇限制范圍的實例代碼

    這篇文章主要介紹了el-date-picker日期選擇限制范圍,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-09-09
  • 詳解Vue3 Composition API中的提取和重用邏輯

    詳解Vue3 Composition API中的提取和重用邏輯

    這篇文章主要介紹了Vue3 Composition API中的提取和重用邏輯,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • Vue Cli3 創(chuàng)建項目的方法步驟

    Vue Cli3 創(chuàng)建項目的方法步驟

    Vue CLI是一個用于快速Vue.js開發(fā)的完整系統(tǒng)。這篇文章主要介紹了Vue Cli3 創(chuàng)建項目的方法步驟,非常具有實用價值,需要的朋友可以參考下
    2018-10-10
  • vue項目中微信登錄的實現(xiàn)操作

    vue項目中微信登錄的實現(xiàn)操作

    這篇文章主要介紹了vue項目中微信登錄的實現(xiàn)操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • vue跨域proxy代理配置詳解

    vue跨域proxy代理配置詳解

    今天被vue中proxy配置困擾了一天,記錄一下,下面這篇文章主要給大家介紹了關(guān)于Vue配置文件中的proxy配置方式的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-08-08
  • vue2.0實現(xiàn)倒計時的插件(時間戳 刷新 跳轉(zhuǎn) 都不影響)

    vue2.0實現(xiàn)倒計時的插件(時間戳 刷新 跳轉(zhuǎn) 都不影響)

    我發(fā)現(xiàn)好多倒計時的插件,刷新都會變成從頭再來,于是自己用vue2.0寫了一個,感覺還不錯,特此分享到腳本之家平臺供大家參考下
    2017-03-03
  • 利用Vue3?+?SpringBoot打造高效Web實時消息推送系統(tǒng)

    利用Vue3?+?SpringBoot打造高效Web實時消息推送系統(tǒng)

    在Vue中實現(xiàn)消息推送,可以通過集成WebSocket服務(wù)來實現(xiàn)實時通信,這篇文章主要介紹了利用Vue3?+?SpringBoot打造高效Web實時消息推送系統(tǒng)的相關(guān)資料,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2025-11-11
  • vue+watermark-dom實現(xiàn)頁面水印效果(示例代碼)

    vue+watermark-dom實現(xiàn)頁面水印效果(示例代碼)

    watermark.js 是基于 DOM 對象實現(xiàn)的 BS 系統(tǒng)的水印,確保系統(tǒng)保密性,安全性,降低數(shù)據(jù)泄密風(fēng)險,簡單輕量,支持多屬性配置,本文將通過 vue 結(jié)合 watermark-dom 庫,教大家實現(xiàn)簡單而有效的頁面水印效果,感興趣的朋友跟隨小編一起看看吧
    2024-07-07
  • 詳解element-ui中el-select的默認選擇項問題

    詳解element-ui中el-select的默認選擇項問題

    這篇文章主要介紹了詳解element-ui中el-select的默認選擇項問題,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • Vue3使用pinia進行數(shù)據(jù)添加、修改和刪除的操作代碼

    Vue3使用pinia進行數(shù)據(jù)添加、修改和刪除的操作代碼

    Pinia?是?Vue?3?的官方狀態(tài)管理庫,旨在提供一種簡單、靈活且類型安全的狀態(tài)管理解決方案,Pinia?的設(shè)計理念與?Vuex?類似,但更加輕量且易于使用,文旨在全面解析?Vue?3?中如何使用?Pinia?進行數(shù)據(jù)的添加、修改和刪除,需要的朋友可以參考下
    2025-03-03

最新評論

达拉特旗| 双鸭山市| 东安县| 怀集县| 平利县| 华宁县| 麦盖提县| 隆化县| 灌南县| 星座| 海淀区| 资阳市| 丹东市| 五指山市| 于都县| 南开区| 孟津县| 呼和浩特市| 定远县| 南充市| 康保县| 喀喇| 东乡| 石景山区| 临西县| 武邑县| 中牟县| 河间市| 台东市| 裕民县| 兰西县| 政和县| 浠水县| 濮阳县| 双牌县| 伊金霍洛旗| 天门市| 尚义县| 垫江县| 辽阳市| 佛冈县|