Building blocks – A step-by-step guide to building a website layout quickly

The project address

This chapter source address

This article addresses

In order to explain the convenience of refactoring and removing Element and VUX libraries, this article uses bulma, which is very popular recently, to be lightweight, fast and easy to read.

Project screenshots

Layout and Components

Layout

First of all, like the figure above, we think of a small website split into three parts: Header, Content, Footer, which is almost every website must have, usually the ten thousand years unchanged: Header, Footer made into a convenient general Layout.

Components

Content is then divided into Components according to business.

As shown above: Header and Content: Header don’t really need to be split. There are no reusable components, and Conntent is the layout element that must be split. Because Conntent, a dynamic site, changes with content, the more content, the higher the probability of reusable things, you need to extract reusable things

1, save code, improve code reading

2. Easy to modify (e.g. updating ads)

Start coding

Then we upload the source code in chapter 2, based on which we continue to improve the small site layout and componentization.

It’s worth noting that this series of tutorials follows one chapter after another and each chapter runs independently, with no “pop up” code snippets. It doesn’t give beginners the feeling that they don’t know where to start. If you’re new to code, you should read the next article carefully. You can either build on the code from the previous chapter step by step or download a brief preview of the code from this chapter.

  • Introduce bulMA style CDN
vim new-bee/index.html
Copy the code
<! -- 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">

Copy the code
  • New Layout directory
vim new-bee/src/renderer/components/layout
Copy the code
  • Create header. vue template components in Layout directory

This component is dedicated to writing header content, preferably with a grid to write as simple and responsive components as possible

<template>

    <div id="bee-header"   element-loading-text="Working to request Github..." element-loading-background="Rgba (0, 0, 0, 0.8)">
        <! - mask - >
        <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="Do a search" required="required" style="Height: 36.4 px; 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">found</a >
              <div class="navbar-dropdown ">
                <a class="navbar-item " type="Collection">collection</a >
                <a class="navbar-item" type="Badge">The badge</a >
                <a class="navbar-item " type="排名">ranking</a >
                <a class="navbar-item "  type="Work Life">Work life</a >
              </div>
            </div>
            <a class="navbar-item " href="https://bulma.io/expo/">
              <! - < span class = "bd - emoji" > ⭐ ️ < / span > -- >column</a >
            <a class="navbar-item " href="https://bulma.io/expo/">
              <! - < span class = "bd - emoji" > ⭐ ️ < / span > -- >chat<! -- Many people don't know what to do... -->
            </a >
            <a class="navbar-item " href="https://bulma.io/expo/">
              <! - < span class = "bd - emoji" > ⭐ ️ < / span > -- >Face the</a >
            <router-link class="navbar-item " to="/book">
              <! - < span class = "bd - emoji" > ❤ ️ < / span > -- >books</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="Do a search" required="required" style=Height: 36.4 px; ""><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="Collection">Write an article</a >
                <a class="navbar-item" type="Badge">Set up the</a >
                <a class="navbar-item " type="排名">exit</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>The login</strong>
                    </a >

                  </p >

                </div>
              </div>
            </div>
          </div>
        </div>
      </nav>
    </div>
  </div>
    </div>
</template>


<script>
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>

Copy the code

What styles can be written in.vue files

The familiar code above is the one that makes our heads round

<style scoped>
.img-circle {
  -webkit-border-radius: 50%;
  -moz-border-radius: 50%;
  border-radius: 50%;
}
Copy the code
  • The effect

I’m just being lazy here to say that for such a generic style, it’s confined to a.vue file marked scoped, declaring it unusable. Any module that wants to use this style will have to make a copy of it, which is obviously not standard, and we usually build generic CSS files to manage it. The CSS management specification for large projects will have a more stringent, standardized tree structure, depending on the CTO.

How to choose layout according to preference

According to the need to introduce

vim new-bee/src/renderer/components/HelloWorld.vue
Copy the code
<template> <div> <Header></Header> <! --<div class="container"> </div>-->
    </div>
</template>

<script>
import Header from "@/components/layout/Header";
export default {
  name: "NewBeeIndex",
  components: { Header },
  data() {
    return {};
  },

  destroyed() {},
  mounted() {},
  methods: {},
  watch: {}
};
</script>
Copy the code

The disadvantage is that you have to introduce it one by one, but the advantage is that the code is readable

Introduced the global

  • App main entrance
vim  new-bee/src/renderer/App.vue
Copy the code
  • The introduction of
<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>


Copy the code
  • See the effect

Thanks to webpack dad’s hot deployment, we didn’t have to refresh the browser, webpack secretly updated our content with WS. It seems perfect, but you may have noticed a problem. We can see it in the dom rendered by the browser:

We introduce the header layout in the main APP entrance, app. vue is the body element of the adjacent element, and all pages and subroutes of this program are subsets of the app. vue entrance, indicating that the global introduction layout will have the following problems:

1. All projects in this project will definitely carry the content rendered by the Header component. 2.

Of course, you could write logical conditions on the Header component to filter the specified routes, but this would break the legibility of the project and make it difficult to maintain

I personally recommend the first approach: on-demand introduction.

Continue to the layout

  • Follow suit and write Footer
vim new-bee/src/renderer/components/layout/Footer.vue
Copy the code
<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"> < p style = "max-width: 100%; clear: both; min-height: 1em; </div> </div> <div> <span class="moto"> Like items can be liked in support of <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>
export default {
  name: "Footer".data() {
    return {};
  },
  created() {},
  destroyed() {},
  mounted() {

  },
  methods: {}
};
</script>

Copy the code

Don’t forget to introduce it in HelloWorld

  • See the effect

  • It looks like it’s working pretty well, and then the Content
vim new-bee/src/renderer/components/layout/Content.vue
Copy the code
<template>

      <div class="container" style="height:700px"> <h1 > List of blogs </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">&nbsp; {{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>
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; The font - size: 1.2 rem; 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; The font - size: 1.8 rem; font-weight: 700; The 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>


Copy the code
  • See the effect

  • The helloWorld.vue code looks like this

Ok, so let’s go on to figure 2

Specify the AD(advertising) component for Content.

vim new-bee/src/renderer/components/common/AD.vue
Copy the code

<template>
     
             <div class="ad"><h1>Macao XX casino is online</h1></div>
    
</template>

<script>
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>
 
Copy the code
  • Don’t forget to introduce it in Content.vue
.<AD></AD>. import AD from "@/components/common/AD"; export default { name: "Content", components: { AD }, ... }Copy the code
  • Look at the effect

  • Compare the sketches we did with Sketch

We’re almost done with our initial concept

conclusion

At this point the page layout and component reference about the end of the story, I believe you can draw inferiorism, write their own small site, which is more complex nesting way is not about, we go directly to see the project.

The author’s words

Actually this project’ve been like this today, just after all the writing tutorials, delay the progress, write the tutorial is not copy and paste, must first guarantee the accuracy, rather than delete censored to hurry, want to write a good tutorial only empathy, as a small white, from the CLI, head to tail one line of code one line of code that pile up. It is no longer the era of jquery.js and vue.js to write scripts (Angular already has IOC). As a back end, the front end is basically here. After Electron, let’s go straight to the project. There’s nothing to talk about. The next chapter will be a separate one. This tutorial is full stack direction, the next step is the backend microservice, message queue, Docker, docker-compose/rancher simulation cluster, operation and maintenance, etc. I will speed up the progress in the future, try to write the whole content before the New Year.

About the reply

New post two days before I go to Denver actually everybody’s comments I can see, but you can imagine, the nuggets news remind no classification: thumb up | |

I can go to github issues each article below leave a message to ask questions, or erratum, paving the way for future generations, the new article will be sent here first one day please erratum, star does not star doesn’t matter, thank you.

The project address

This chapter source address

This article addresses

The articles

Sequencing – Meaning of open source

Introduction – A look at the history of the WEB

Explore – Talk in depth about the pre – and post-separation architecture

Ready? – Did you clear the front end? Front-end infrastructure and technology introduction

Real – 5 minutes to quickly build a standard front end project skeleton

Practice – Continue to polish the front-end architecture in order to get ahead of the game

Perfect – Hand by hand to teach you how to quickly build a website layout

The next chapter is “The End of the Front-end – Front-end Performance Optimization and Rollout”.