Electron使用指南 - [10] 构建 Vue 项目基本结构

准备 Header, Main, 和 Modal 三个组件。

1、reset.css 样式

编写 reset.css 样式:

/* /src/assets/styles/reset.css */

html, body {
  height: 100%;
}

body {
  font: caption;
  margin: 0;
  display: flex;
  flex-flow: column;
}

2、App 根组件

编辑 /renderer/src/App.vue

<template>
  <div>
    <Header></Header>
    <Main></Main>
    <Modal></Modal>
  </div>
</template>

<script>
import Header from './components/Header'
import Main from './components/Main'
import Modal from './components/Modal'

export default {
  components: {
    Header,
    Main,
    Modal
  }
}
</script>

<style lang='stylus' scoped>
div
  height 100%
  position relative
</style>

3、Header 组件

在 components 文件夹下创建 Header.vue 组件: /src/components/Header.vue

<template>
  <header>
    <button id="show-modal">+</button>
    <input type="text" id="search" placeholder="Search">
  </header>
</template>

<script>
export default {

}
</script>

<style lang='stylus' scoped>
button {
  background: dodgerblue;
  color: white;
  border-radius: 5px;
  border: none;
  font-size: 20px;
  outline: none;
}

input {
  font-size: 20px;
  border-radius: 5px;
  border: 1px solid silver;
  padding: 0 10px;
}

input::placeholder {
  color: lightgray;
}

header {
  background: lightgray;
  display: flex;
  padding: 10px;
  font-weight: bold;
  border-bottom: 1px solid silver;
  box-shadow: 0px 10px 10px rgba(0,0,0,0.1);
}

#show-modal {
  padding: 0px 12px 5px;
  margin-right: 10px;
  font-size: 30px;
}

#search {
  flex-grow: 1;
}
</style>

4、Main 组件

在 components 文件夹下创建 Main.vue 组件: /src/components/Main.vue

<template>
  <main>
    <p id="no-items">No Items</p>
    <div id="items"></div>
  </main>
</template>

<script>
export default {

}
</script>

<style lang='stylus' scoped>
#items {
  flex-grow: 1;
}

#no-items {
  font-weight: bold;
  color: silver;
  text-align: center;
  width: 100%;
  position: absolute;
  top: 100px;
  z-index: -1;
}
</style>

5、modal 组件

在 components 文件夹下创建 Modal.vue 组件: /src/components/Modal.vue

<template>
  <div id="modal">
    <input type="text" id="url" placeholder="Enter URL">
    <button id="add-item">Add Item</button>
    <button id="close-modal">Cancel</button>
  </div>
</template>

<script>
export default {

}
</script>

<style lang='stylus' scoped>
#modal {
  position: absolute;
  top 0;
  left 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  align-content: center;
  flex-wrap: wrap;
  display: none;
}

#url {
  flex-grow: 1;
  width: 100%;
  margin: 0 25px 15px;
  padding: 10px;
}

#modal button {
  padding: 10px;
}

#close-modal {
  background: white;
  color: black;
  margin-left: 15px;
}

#add-item {
  margin-left: 25px;
}

.read-item {
  display: flex;
  align-items: center;
  align-content: center;
  border-bottom: lightgray 2px solid;
  background: #FAFAFA;
  padding: 10px;
}

.read-item img {
  width: 20%;
  margin-right: 25px;
}
</style>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 项目准备 在码云新建仓库travel 克隆到本地 在本地仓库所在目录执行 选择y表示继续 样式重置 index.h...
    alfalfaw阅读 3,707评论 0 0
  • 主体结构 package.json npm install命令根据这个配置文件增减来管理本地的安装包。 devDe...
    oWSQo阅读 6,102评论 0 1
  • 生成webpack模板 如果已经安装了vue-cli,在项目根目录所在的目录下,执行下面命令。 如果没有安装vue...
    V火力全开阅读 6,389评论 0 2
  • vue-cli构建项目成功后,项目目录整体结构如下 1.build文件夹下的文件如下,执行npm run命令时执行...
    z小牛阅读 3,427评论 0 1
  • 前言 接触vue框架也有一个多月的时间了,整理下之前做过的一个小demo,主要是熟悉vue全家桶技术,界面布局模仿...
    视觉派Pie阅读 26,753评论 20 285