03 - Vue3 UI Framework - 首頁


頂部邊欄做完了,接下來開始做官網的首頁

返回閱讀列表點擊 這里

創建視圖文件夾

讓我們先新建一個 src/views 文件夾,用來存放官網的主要視圖

然后在該文件夾下新建兩個 vue 文件,作為我們的視圖

  • Home.vue,首頁
  • Document.vue,文檔頁

再配置一下 router.ts 來實現跳轉

import { createWebHistory, createRouter } from 'vue-router'
import Home from './views/Home.vue'
import Document from './views/Document.vue'

const history = createWebHistory()
const router = createRouter({
  history,
  routes: [
    { path: '/', component: Home },
    { path: '/document', component: Document },
  ]
})
export default router

骨架

先搭建一下首頁的骨架

已知首頁要顯示

  1. 頂邊欄
  2. 極光背景
    • 兩個跳轉鏈接
  3. 三點特性

首先是極光背景,非常簡單,用漸變色 + 轉向當作背景色就可以了,然后三點特性,顯然是無序列表,那么可以得到如下骨架:

<template>
  <div>
    <Topnav />
    <div class="banner">
      <a href="https://github.com/JeremyWu917/jeremy-ui"> Github </a>
      <router-link to="/document"> 文檔頁 </router-link>
    </div>
    <div class="features">
      <ul>
        <li>特性1</li>
        <li>特性2</li>
        <li>特性3</li>
      </ul>
    </div>
  </div>
</template>

基本功能

然后在 script 中引入頂邊欄

import Topnav from "../components/Topnav.vue";
export default {
  components: {
    Topnav,
  },
};

最后制作一下極光的樣式表


<style lang="scss" scoped>
$theme-color: #8c6fef;
$border-radius: 4px;
$color: white;
.banner {
  background: linear-gradient(
    145deg,
    rgb(232, 232, 235) 0%,
    rgb(193, 181, 235) 30%,
    rgb(136, 106, 235) 70%,
    rgb(108, 68, 240) 100%
  );
  clip-path: ellipse(80% 60% at 50% 40%);
}
.features {
  margin: 64px auto;
  padding: 0 16px;
  @media (min-width: 800px) {
    width: 800px;
    > ul {
      > li {
        width: 50%;
      }
    }
  }
  @media (min-width: 1200px) {
    width: 1200px;
    > ul {
      > li {
        width: 33.3333%;
      }
    }
  }
  @media (max-width: 800px) {
    > ul {
      flex-direction: column;
      align-items: center;
    }
  }
  > ul {
    display: flex;
    flex-wrap: wrap;
    > li {
      margin: 16px 0;
      display: grid;
      justify-content: center;
      align-content: space-between;
      grid-template-areas:
        "icon title"
        "icon text";
      grid-template-columns: 80px auto;
      grid-template-rows: 1fr auto;
      > svg {
        grid-area: icon;
        width: 64px;
        height: 64px;
      }
      > h3 {
        grid-area: title;
        font-size: 28px;
      }
      > p {
        grid-area: text;
      }
    }
  }
}
.banner {
  color: $color;
  padding-top: 120px;
  padding-bottom: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  > * {
    margin: 12px 0;
  }
  > .actions {
    padding: 8px 0;
    a {
      margin: 0 8px;
      display: inline-block;
      padding: 8px 24px;
      &:hover {
        text-decoration: none;
      }
      > img {
        display: block;
        width: 80px;
      }
      text-align: center;
    }
  }
}
</style>

改進首頁

那顯然,特性應該單獨占據一行,並且在寬度足夠的時候橫向排列,兩個鏈接也最好橫向排列,而且最好各自有點介紹。

先修改模板,再補全樣式,再加個 SVG 圖,home.vue 代碼如下:

<template>
  <div>
    <Topnav />
    <div class="banner">
      <h1>Jeremy UI</h1>
      <h2>JeremyWU 創建的 UI 組件庫</h2>
      <p class="actions">
        <a href="https://github.com/JeremyWu917/jeremy-ui">
          <img
            src="../assets/github.png"
            alt="Github"
            style="transform: rotateY(180deg)"
          />
          Github
        </a>
        <router-link to="/document">
          <img src="../assets/goto.png" alt="開始" />
          開始
        </router-link>
      </p>
    </div>
    <div class="features">
      <ul>
        <li>
          <svg>
            <use xlink:href="#icon-Vue"></use>
          </svg>
          <h3>基於 Vue 3</h3>
          <p>使用了 Vue 3 全新特性</p>
        </li>
        <li>
          <svg>
            <use xlink:href="#icon-typescript"></use>
          </svg>
          <h3>基於 TypeScript</h3>
          <p>源代碼采用 TypeScript 書寫</p>
        </li>
        <li>
          <svg>
            <use xlink:href="#icon-fork"></use>
          </svg>
          <h3>具有親和力的代碼</h3>
          <p>新手也能輕松閱讀的源代碼</p>
        </li>
      </ul>
    </div>
  </div>
</template>

<script lang="ts">
import Topnav from "../components/Topnav.vue";
export default {
  components: {
    Topnav,
  },
};
</script>

<style lang="scss" scoped>
$theme-color: #8c6fef;
$border-radius: 4px;
$color: white;
.banner {
  background: linear-gradient(
    145deg,
    rgb(232, 232, 235) 0%,
    rgb(193, 181, 235) 30%,
    rgb(136, 106, 235) 70%,
    rgb(108, 68, 240) 100%
  );
  clip-path: ellipse(80% 60% at 50% 40%);
}
.features {
  margin: 64px auto;
  padding: 0 16px;
  @media (min-width: 800px) {
    width: 800px;
    > ul {
      > li {
        width: 50%;
      }
    }
  }
  @media (min-width: 1200px) {
    width: 1200px;
    > ul {
      > li {
        width: 33.3333%;
      }
    }
  }
  @media (max-width: 800px) {
    > ul {
      flex-direction: column;
      align-items: center;
    }
  }
  > ul {
    display: flex;
    flex-wrap: wrap;
    > li {
      margin: 16px 0;
      display: grid;
      justify-content: center;
      align-content: space-between;
      grid-template-areas:
        "icon title"
        "icon text";
      grid-template-columns: 80px auto;
      grid-template-rows: 1fr auto;
      > svg {
        grid-area: icon;
        width: 64px;
        height: 64px;
      }
      > h3 {
        grid-area: title;
        font-size: 28px;
      }
      > p {
        grid-area: text;
      }
    }
  }
}
.banner {
  color: $color;
  padding-top: 120px;
  padding-bottom: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  > * {
    margin: 12px 0;
  }
  > .actions {
    padding: 8px 0;
    a {
      margin: 0 8px;
      display: inline-block;
      padding: 8px 24px;
      &:hover {
        text-decoration: none;
      }
      > img {
        display: block;
        width: 80px;
      }
      text-align: center;
    }
  }
}
</style>

運行效果

image-20211211102354207

項目地址 🎁

GitHub: https://github.com/JeremyWu917/jeremy-ui

官網地址 🌍

JeremyUI: https://ui.jeremywu.top

感謝閱讀 ☕


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM