这是我参与更文挑战的第14天,活动详情查看:更文挑战css
此系列的目的是帮助前端新人,熟悉现代前端工程化开发方式与相关技术的使用,普及一些通识内容html
为提高阅读体验,文章将会分为多节发布,本节主要阐述前端部分前端
女友每天都在念叨:"我又胖了,怎么不吃东西也没见轻"vue
为了记录每次体重数据的变化,就下载了记录体重的App,用了几个都不太满意(主要是不满意数据反映出的图表内容)react
因而乎咱就拿出键盘⌨🖰就给她打造一个独一无二的ios
长话短说:git
明确了目标用户与用户诉求后,接下来直接定技术方案github
应用形式:H5(移动到Web应用)web
均使用Serverless服务部署,性能好又便宜vue-router
直接使用搭建的ATQQ/vite-vue3-template模板初始化项目
添加依赖
yarn add vant@next
复制代码
配置按需引入
// vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import styleImport from 'vite-plugin-style-import'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
styleImport({
libs: [
{
libraryName: 'vant',
esModule: true,
resolveStyle: (name) => `vant/es/${name}/style`,
},
],
}),
]
})
复制代码
// src/utils/vantUI.ts
import { App } from '@vue/runtime-core'
// 按需引入
import { Button } from 'vant'
const conponents = [Button]
export default function mountVantUI(app: App<Element>) {
conponents.forEach((c) => {
app.component(c.name, c)
})
}
复制代码
一期预计4个页面:
快速创建好4个页面的模板
# src/pages/
├── 404 # 404
| └── index.vue
├── dashboard # 功能面板
| └── index.vue
├── funcs
| └── weight # 体重记录
| └── index.vue
├── home # 首页
| └── index.vue
└── login # 登陆页
└── index.vue
directory: 6 file: 5
复制代码
页面肯定后,配置一下页面路由
src/router/routes/index.ts
import { RouteRecordRaw } from 'vue-router'
import Home from '../../pages/home/index.vue'
const NotFind = () => import('../../pages/404/index.vue')
const Login = () => import('../../pages/login/index.vue')
const DashBoard = () => import('../../pages/dashboard/index.vue')
const Weight = () => import('../../pages/funcs/weight/index.vue')
const routes: RouteRecordRaw[] = [
{ path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFind },
{
path: '/',
name: 'index',
component: Home,
},
{
path: '/login',
name: 'login',
component: Login,
},
{
path: '/dashboard',
name: 'dashboard',
component: DashBoard,
},
{
path: '/funs/weight',
name: 'weight',
component: Weight,
},
]
export default routes
复制代码
将顶层的router-view
组件放在App.vue中
src/App.vue
<template>
<div class="app">
<router-view></router-view>
</div>
</template>
复制代码
首先在html模板中添加一句
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
复制代码
尺寸单位使用rem方案,设计稿按375来定
经过调研现有的响应式网站与模拟器中实测,尺寸主要由320
,360
,375
,414
四种,得出如下结果:
因而乎能够直接使用 媒体查询
处理单位的设置
在App.vue
中加入得出的以下代码:
<style> @media screen and (min-width: 320px) { html { font-size: 12px; } } @media screen and (min-width: 360px) { html { font-size: 13.5px; } } @media screen and (min-width: 375px) { html { font-size: 14.0625px; } } </style>
复制代码
注意:因为样式权重同样的状况下,会采用后定义的内容,因此大尺寸媒体查询代码的放在后面
TODO:补样式权重计算文章
不排除用户电脑访问应用的状况,为提高用户体验,将顶层容器标签
固定为414px
在App.vue
中加入以下代码:
<style scoped> .app { max-width: 414px; margin: 0 auto; } </style>
复制代码
准备工做基本完成后就开始糊页面
因为糊页面是个体力活儿,没有养分,文中只贴一些关键代码,完成代码,去仓库探索
页面使用@vue/compiler-sfc
方案,开发提效,代码更直观
使用的渐变色来源:webgradients
页面总体上只包含应用名
,简介
,导航登陆
3部分
<template>
<div class="home">
<h1 class="title">时光恋人</h1>
<!-- 简介 -->
<section class="introduce">
<p v-for="(item, index) in introduces" :key="index">{{ item }}</p>
</section>
<section class="introduce">
<p>
<router-link to="/login">
<van-button size="small" round :color="loginColor">点击体验</van-button>
</router-link>
</p>
</section>
</div>
</template>
<script lang="ts" setup>
import { reactive } from 'vue'
const introduces: string[] = reactive(['记录情侣之间', '平常生活趣事,生活足迹'])
const loginColor = 'linear-gradient(to right, #b8cbb8 0%, #b8cbb8 0%, #b465da 0%, #cf6cc9 33%, #ee609c 66%, #ee609c 100%)'
</script>
复制代码
避免繁琐的注册流程,直接使用短信验证码登陆方案
这个页面开发了一个自定义的 Input
组件
效果以下,包含icon
,输入区域
,输入提示
,注意提示
4部份内容
Dom结构以下
<template>
<div class="under-input">
<van-icon class="icon" v-if="icon" :name="icon" />
<input
:maxlength="maxLength"
:placeholder="placeholder"
:type="type"
:value="modelValue"
@input="handleInput"
/>
</div>
<p v-if="tips" class="tips">
{{ tips }}
</p>
</template>
复制代码
输入内容使用简单的正则进行校验
// 手机号
export const rMobile = /^[1]\d{10}$/
// 验证码
export const rCode = /\d{4}/
复制代码
调研了一些相似的应用,最终选择采用卡片的形式展示各个功能入口
卡片组件主要包含功能介绍与彩色图标两部分,效果以下
Dom结构以下:
<template>
<div
class="fun-card"
:class="{
disabled,
}"
>
<div>
<h1 class="title">{{ title }}</h1>
</div>
<span v-if="icon" :class="[icon]" class="iconfont icon"></span>
<!-- lock -->
<div v-if="disabled" class="lock">
<span class="icon-lockclosed iconfont"> </span>
</div>
</div>
</template>
复制代码
iconfont
只须要简单的在模板中引入css资源,使用的时候直接书写class便可
<!-- index.html -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_2609471_9womj4g1e15.css">
复制代码
<!-- 使用图标 -->
<span class="icon-lockclosed iconfont"> </span>
复制代码