Wiidede's blog Wiidede's blog
  • 前端
  • Python
  • 算法
  • 生活
  • 其他
  • 分类
  • 标签
  • 归档
  • 关于我
  • 赞赏
  • 我的小站 (opens new window)
GitHub (opens new window)

Wiidede

小的的写前端
  • 前端
  • Python
  • 算法
  • 生活
  • 其他
  • 分类
  • 标签
  • 归档
  • 关于我
  • 赞赏
  • 我的小站 (opens new window)
GitHub (opens new window)
  • 整理一些css样式
  • vue隔代组件层层动态插槽并且附带数据
  • vue判断字符串是否溢出来显示弹窗、解决el-table tooltip 内过多导致无法显示,内容闪烁
  • 整理一些js写法
  • ElementUI timePicker 增加此刻按钮 引发的dom操作的学习
  • 毕业设计(水表识别)前端知识整理
    • 技术点:
    • 部分实现
      • App.vue
      • header
      • 复制到剪贴板
    • 总结
  • html小知识
  • axios请求api然后下载文件
  • vue3+ts根据高度改变元素的透明度
  • vue3 + ElementPlus 换肤方案(Css变量)
  • Moment的一些使用方法
  • echarts基础vue组件
  • element UI el-date-picker 年月日切换组件
  • 可以不选择的el-radio单选框
  • vue的小技巧总结
  • 全局动态权限判断(Vue指令)
  • vue-anchor 探索
  • Deep Dive with Evan You 笔记
  • 前端基础知识查漏补缺
  • WebPack 知识总结
  • 我写的一些可以日后参考的代码
  • 接口变化后,封装接口函数,改变返回内容
  • 项目组件整理
  • 前端框架设计想发
  • 全局进度条
  • 带有token的图片vue组件:authImg,使用axios下载图片
  • 前端npm包推荐
  • 给ElInputNumber添加prefix
  • ElPagination添加页数总数
  • el-tab做成chrome类似的tab样式
  • vue-grid-layout-组件配置
  • 项目数据字典封装
  • 图表组件响应式探索
  • ElementPlus表格table列自动合并composition
  • 简单的curd组件封装
  • ElementPlus表格自定义合计列composition
  • 一些处理表格数据composition api
  • div内容溢出后,内容向左悬浮,vue组件封装
  • 文本数字溢出后,按比例缩小,vue组件封装
  • 表格使用async-validator检验composition
  • ElementPlus Form一些简单的组件整合
  • arco-design快速使用tailwind的颜色、unocss动态颜色
  • 前端
wiidede
2021-06-04

毕业设计(水表识别)前端知识整理

# 毕业设计(水表识别)前端知识整理

大学毕业设计刚刚做完,做的是水表识别,整个项目源代码放在了github (opens new window) gitee (opens new window),前端比较简单,用来上传图片并且展示识别结果。

# 技术点:

  • Vue3.0
  • Element Plus
  • Vue-Cli 4.5

# 部分实现

# App.vue

这里先把整个页面的结构布置完毕,并且我们使用el-scrollbar组件来包裹整个页面以现实更好的滚动条。

我也引入自己写好的header和footer组件,使结构更为清楚。

具体代码如下:

<template>
  <wm-header></wm-header>
  <el-scrollbar ref="scrollViewRef">
    <router-view v-slot="{ Component }" class="pt-4 pb-4" style="min-height: calc(100vh - 120px)">
      <keep-alive>
        <component :is="Component"></component>
      </keep-alive>
    </router-view>
    <wm-footer></wm-footer>
  </el-scrollbar>
</template>
1
2
3
4
5
6
7
8
9
10
11

为了每次切换能够让页面移到最上面,我们在setup函数中加入对路由的监听。

<script>
export default {
  setup () {
    const scrollViewRef = ref(null)
    const router = useRouter()
    router.beforeEach(() => {
      if (scrollViewRef.value) {
        scrollViewRef.value.wrap.scrollTop = 0
      }
    })
    return { scrollViewRef }
  }
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14

因为是直接设置容器的scrollTop,所以我们给容器加入平滑滚动的样式:

.el-scrollbar__wrap {
  scroll-behavior: smooth;
}
1
2
3

# header

在header组件,我们把需要放在右上角的tab放入数组headList中,方便维护。

然后我们动态监听当前页面的路由,这里我们直接使用Vue 3的WatchEffect,判断tab数组中的链接是否与当前的路由相等,如果相等的话,即改变这个tab的样式。

wm-header.vue 代码如下:

<template>
  <el-header class="w-100 d-flex align-items-center justify-content-between">
    <router-link to="/" class="header-title logo">水表识别系统</router-link>
    <div class="right-header d-flex align-items-center h-100">
      <router-link :to="head.path" v-for="(head, index) in headList" :key="`head-${index}`" :class="{active: head.active}"
                   class="header-item h-100 mr-1 ml-1 pl-3 pr-3">
        <div class="header-item-text h-100 d-flex align-items-center">{{ head.label }}</div>
      </router-link>
    </div>
  </el-header>
</template>

<script>
import { reactive, watchEffect } from 'vue'
import { useRouter } from 'vue-router'

export default {
  name: 'wm-header',
  setup () {
    const headList = reactive( // tab列表放在这个变量
      [
        { path: '/', label: '主页', active: false },
        { path: '/about', label: '关于', active: false }
      ]
    )
    const router = useRouter() // 使用 vue3 的 useRouter() 来获取当前的路由
    watchEffect(() => { // watchEffect() 会监听代码中有变化的值,来执行函数
      headList.forEach(head => {
        head.active = router.currentRoute.value.path === head.path
      })
    })
    return { headList }
  }
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

# 复制到剪贴板

对于结果页面,我们需要写一个复制到剪贴版的函数,我们把这个函数抽离到utils.js中

我们需要传入需要复制的内容、以及成功、失败分别需要调用的函数。

export const copyToClipboard = (content, successFunc, errorFunc) => {
  const tempEl = document.createElement('input')
  tempEl.setAttribute('value', content)
  document.body.appendChild(tempEl)
  tempEl.select()
  if (document.execCommand('copy')) {
    successFunc && typeof successFunc === 'function' && successFunc()
  } else {
    errorFunc && typeof errorFunc === 'function' && errorFunc()
  }
  document.body.removeChild(tempEl)
}
1
2
3
4
5
6
7
8
9
10
11
12

然后我们就可以在vue组件中使用这个函数:

import { copyToClipboard } from '../../utils'    
const copy = (content) => {
  copyToClipboard(
    content,
    () => ElMessage.success('已复制到剪贴板'),
    () => ElMessage.error('复制失败')
  )
}
1
2
3
4
5
6
7
8

# 总结

前端的页面比较简单,重点的代码基本就是上面这些。

这次毕设主要是尝试vue 3.0,试着写组合Api。

你可以在这里查看我的后端项目整理

#前端#毕业设计#Vue
上次更新: 2023/06/01, 12:40:50

← ElementUI timePicker 增加此刻按钮 引发的dom操作的学习 html小知识→

Theme by Vdoing | Copyright © 2021-2023 Wiidede | Website use MIT License | Article content & logo use CC-BY-SA-4.0 License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式