时间:2023-05-29 01:27:01 | 来源:网站运营
时间:2023-05-29 01:27:01 来源:网站运营
《从零构建前后分离的web项目》前端完善 - 手把手教你快速构建网站布局:项目截屏
值得一提的是:本系列教程一章跟随一章并且每一章可以独立运行,章与章之间完美衔接,没有 “突然出现” 的代码段。不会给新手无从下手的感觉,如果那你对代码陌生,那你该认真翻翻往期文章了。你可以基于上一章逐步写代码,也可以下载本章简单预览代码。
vim new-bee/index.html<!-- font --> <link href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> <!-- css --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.0/css/bulma.min.css">
vim new-bee/src/renderer/components/layout
<template> <div id="bee-header" element-loading-text="正在努力请求github..." element-loading-background="rgba(0, 0, 0, 0.8)"> <!-- 遮罩 --> <div :class=" loading ? `modal is-active` : `modal` " style="background-color: #ffffff36"> < img src="https://img.actd.tw/images/2018/11/17/ezgif-4-05f4bba41fef.gif" style="width: 300px" alt=""> </div> <div class="is-underline "> <div class="container"> <nav class="navbar "> <div class="navbar-brand"> <a class="navbar-item" > < img src="https://img.actd.tw/images/2018/11/17/bee.png" alt="Bulma: a modern CSS framework based on Flexbox" width="92" height="28"> </a > <div class="login-before is-hidden-mobile" style="padding-top: 5px;"> <a class="navbar-item is-hidden-desktop" href=" " target="_blank"> <span class="icon" style="color: #333;"> <i class="fa fa-lg fa-github is-size-2"></i> </span> </a > </div> <div class="navbar-item is-hidden-desktop "> <div class="field has-addons" ><div class="control" ><input type="input" class="input" name="email" placeholder="搜索一下" required="required" style="height: 36.4px;width:130px"><input type="hidden" name="redirect" id="name" value="/fr/#thanks"></div><div class="control" ><input type="submit" class="button is-warning" value="GO"></div></div> </div> <div class="navbar-burger burger" data-target="navMenuDocumentation" > <span></span> <span></span> <span></span> </div> </div> <div id="navMenuDocumentation" class="navbar-menu"> <div class="navbar-start"> <div class="navbar-item has-dropdown is-hoverable"> <a class="navbar-link is-active"> 发现 </a > <div class="navbar-dropdown "> <a class="navbar-item " type="收藏集"> 收藏集 </a > <a class="navbar-item" type="徽章"> 徽章 </a > <a class="navbar-item " type="排名"> 排名 </a > <a class="navbar-item " type="职场生活"> 职场生活 </a > </div> </div> <a class="navbar-item " href="https://bulma.io/expo/"> <!--<span class="bd-emoji">⭐️</span>--> 专栏 </a > <a class="navbar-item " href="https://bulma.io/expo/"> <!--<span class="bd-emoji">⭐️</span>--> 聊天 <!-- 很多人不知道干什么。。。 --> </a > <a class="navbar-item " href="https://bulma.io/expo/"> <!--<span class="bd-emoji">⭐️</span>--> 面经 </a > <router-link class="navbar-item " to="/book"> <!--<span class="bd-emoji">❤️</span>--> 书籍 </router-link> </div> <div class="navbar-end"> <div class="login-before" style="padding-top: 5px;"> <!-- pc --> <a class="navbar-item is-hidden-desktop-only" href="https://github.com/pkwenda/my-bbs" target="_blank"> <span class="icon" style="color: #333;"> <i class="fa fa-lg fa-github is-size-2"></i> </span> </a > </div> <div class="navbar-item is-hidden-mobile "> <div class="field has-addons" ><div class="control" ><input type="input" class="input" name="email" placeholder="搜索一下" required="required" style="height: 36.4px;"><input type="hidden" name="redirect" id="name" value="/fr/#thanks"></div><div class="control" ><input type="submit" class="button is-warning" value="GO"></div></div> </div> <div class="navbar-item is-hidden-mobile "> <!--<span class="icon is-medium">--> <i class="iconfont icon-tixing"></i> <!--</span>--> </div> <div class="navbar-item has-dropdown is-hoverable"> <a class="is-hidden-mobile" target="_blank"> < img src="https://avatars2.githubusercontent.com/u/14212375?s=400&u=dc515636befebfda36501309d1cdc087ee31d500&v=4" class=" header-avatar img-circle " style="margin-top: 10px"> </a > <div class="navbar-dropdown "> <a class="navbar-item " type="收藏集"> 写文章 </a > <a class="navbar-item" type="徽章"> 设置 </a > <a class="navbar-item " type="排名"> 退出 </a > </div> </div> <div class="login-before"> <div class="navbar-item"> <div class="field is-grouped"> <p class="control"> <a class="button is-warning" v-show="!isLogin" > <strong>登录</strong> </a > </p > </div> </div> </div> </div> </div> </nav> </div> </div> </div></template><script>import _ from "lodash";export default { name: "BeeHeader", data() { return { popupShow: false, isLogin: false, user: {}, loading: false, userInfo: {} }; }, created() {}, destroyed() {}, mounted() {}, methods: {}};</script><style scoped>.img-circle { -webkit-border-radius: 50%; -moz-border-radius: 50%; border-radius: 50%;}</style>
<style scoped>.img-circle { -webkit-border-radius: 50%; -moz-border-radius: 50%; border-radius: 50%;}
vim new-bee/src/renderer/components/HelloWorld.vue<template> <div> <Header></Header> <!--<div class="container"> </div>--> </div></template><script>import Header from "@/components/layout/Header";import _ from "lodash";export default { name: "NewBeeIndex", components: { Header }, data() { return {}; }, destroyed() {}, mounted() {}, methods: {}, watch: {}};</script>
缺点是要一个一个引入,但优点是代码可读性高
vim new-bee/src/renderer/App.vue
<template> <div id="app"> <Header></Header> <!-- < img src="./assets/logo.png"> --> <router-view/> </div></template><script>import Header from "@/components/layout/Header";export default { name: "App", components: { Header }};</script><style></style>
当然可以再 Header 组件上书写逻辑条件,过滤指定的路由,但会破坏项目的易读性,难以维护
我个人是比较推荐第一种:按需引入的方式。
vim new-bee/src/renderer/components/layout/Footer.vue<template> <footer class="footer footer-light-medium " style="padding-bottom: 20px;padding-top: 20px;"> <div class="container"> <div class="columns"> <!-- Column --> <div class="column is-4"> <div class="mb-20"> < img class="small-footer-logo" src="https://img.actd.tw/images/2018/11/17/bee.png" alt=""> <div class="footer-description pt-10"> new bee 是一个为开发者提供的专注于技术分享的开源社区,所有源码均可在 github 上找到,希望对广大开发者有所帮助。 </div> </div> <div> <span class="moto">喜欢项目可以点赞支持 <a href="https://github.com/pkwenda/new-bee" target="_blank"> <span class="icon"><i class="fa fa-github"></i></span> </a >.</span> <div class="social-links mt-20"> </div> </div> </div> <!-- Column --> <div class="column is-6 is-offset-2"> <div class="columns"> <!-- Column --> <div class="column"> <ul class="footer-column"> <li class="column-header"> Links </li> <li class="column-item"><a href="https://github.com/pkwenda/new-bee">Home</a ></li> <li class="column-item"><a href="https://cssninja.io/themes">Blog</a ></li> <li class="column-item"><a href="https://github.com/pkwenda/new-bee/wiki">Wiki</a ></li> </ul> </div> <!-- Column --> <div class="column"> <ul class="footer-column"> <li class="column-header"> Ressources </li> <li class="column-item"><a href="https://cssninja.io/help">Help center</a ></li> <li class="column-item"><a href="https://cssninja.io/blog">Blog</a ></li> <li class="column-item"><a href="https://cssninja.io/help/rules">Rules</a ></li> </ul> </div> <!-- Column --> <div class="column"> <ul class="footer-column"> <li class="column-header"> Terms </li> <li class="column-item"><a href="https://cssninja.io/help/terms/licenses/personal">Personal</a ></li> <li class="column-item"><a href="https://cssninja.io/help/terms/licenses/developer">Developer</a ></li> <li class="column-item"><a href="https://cssninja.io/help/terms/service">Terms of Service</a ></li> </ul> </div> </div> </div> </div> </div></footer></template><script>import _ from "lodash";export default { name: "Footer", data() { return {}; }, created() {}, destroyed() {}, mounted() { this.auto(); }, methods: {}};</script>
别忘了在 HelloWorld 引入一下
vim new-bee/src/renderer/components/layout/Content.vue<template> <div class="container" style="height:700px"> <h1 >博客列表</h1> <article class="column is-3" v-for="blog in blogs" v-bind:key="blog"> <a class="bd-article-image is-bootstrap" > <span class="bd-article-overlay"></span> <span class="bd-article-icon"> <i class="fa fa-tag"></i> </span> <strong class="bd-star-icon" ><i class="fa fa-star"></i> <span style="font-size: 1rem"> {{blog.commendCount}}</span></strong> <strong class="bd-article-info"> <span> <time class="bd-article-date" datetime="2017-10-09T00:00:00+00:00"> {{blog.tag}} </time> <strong class="bd-article-title"> {{blog.title}} </strong> </span> </strong> </a> </article> </div></template><script>import _ from "lodash";let article = { tag: "java", title: "java", commendCount: 0 };export default { name: "Footer", data() { return { blogs: [ article, article, article, article, article, article, article, article ] }; }, created() {}, destroyed() {}, mounted() {}, methods: {}};</script><style scoped>.bd-article-image.is-bootstrap { background-color: #6f5499;}.bd-article-image { background-color: #00d1b2; display: block; height: 240px; margin-left: auto; margin-right: auto; position: relative; text-align: center;}.bd-star-icon { font-size: 19.2px; font-size: 1.2rem; color: #0a0a0a; opacity: 0.25; bottom: 10px; left: 30px; position: absolute; -webkit-box-align: center; -ms-flex-align: center; -webkit-align-items: center; align-items: center; display: -webkit-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -webkit-box-pack: center; -ms-flex-pack: center; -webkit-justify-content: center; justify-content: center;}.bd-article-icon,.bd-article-info { bottom: 0; left: 0; position: absolute; right: 0; top: 0; -webkit-box-align: center; -ms-flex-align: center; align-items: center; display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center;}.bd-article-info { padding: 20px;}a strong { color: currentColor;}.bd-article-date { color: rgba(0, 0, 0, 0.5); display: block;}.bd-article-title { color: white; display: block; font-size: 1.8rem; font-weight: 700; line-height: 1.25; padding: 0 20px;}.bd-article-icon { color: #0a0a0a; opacity: 0.25;}h1 { text-align: center; font-size: 30px;}.column.is-3,.column.is-3-tablet { -webkit-box-flex: 0; -ms-flex: none; flex: none; width: 25%; float: left;}</style>
vim new-bee/src/renderer/components/common/AD.vue<template> <div class="ad"><h1>澳门皇家赌场上线啦</h1></div></template><script>import _ from "lodash";export default { name: "AD", data() { return {}; }, destroyed() {}, mounted() {}, methods: {}, watch: {}};</script> <style scoped>.ad { width: 150px; height: 180px; background-color: #ececec; position: fixed; right: 30px; top: 80px;}</style>
...<AD></AD>...import AD from "@/components/common/AD";export default { name: "Content", components: { AD }, ... }
关键词:把手,布局,分离,项目,完善