百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术分类 > 正文

Element UI实现基本的布局,以及引用Echars

ztj100 2024-12-03 06:54 62 浏览 0 评论

导入Element ui插件

npm i element-ui -S

配置Element UI

在src文件夹下的main.js的配置如下

代码为:

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

Vue.config.productionTip = false
Vue.use(ElementUI)

然后在组件中使用Element UI

具体的使用方法大家到Element UI官网中进行选择,官网地址为

https://element.eleme.cn/#/zh-CN

大家根据需要选择组件


这是我根据B站的视频仿出来的一个布局


代码如下:

<template>
  <div>
    <el-container>
      <el-header>车载物联网无线通信滑移门运行数据回传系统</el-header>
      <el-main>
        <div id="car-speed" class="car-speed"></div>
        <div class="car-position"></div>
        <div class="show-other"></div>
        <div class="car-count"></div>
        <div class="car-status"></div>
      </el-main>
      <el-footer>Footer</el-footer>
    </el-container>
  </div>
</template>



<script>
export default {
  mounted() {
    this.setChar()
  },

  name: 'Data',
  components: {
    //组件
  },

  methods: {
    setChar() {
    let myChart = this.$echarts.init(document.getElementById('car-speed'), 'white')
      var option = {
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
        },
        yAxis: {
          type: 'value',
        },
        series: [
          {
            data: [150, 230, 224, 218, 135, 147, 260],
            type: 'line',
          },
        ],
      }
      // 绘制图表
      myChart.setOption(option);
    },
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style  scoped >
.el-header,
.el-footer {
  height: 240px;
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-main {
  height: 600px;
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

.car-speed {
  margin-left: 5px;
  width: 500px;
  height: 300px;
  background-color: black;
  border-radius: 15px 15px 0 0;
}

.car-position {
  position: absolute;
  margin-top: 20px;
  margin-left: 5px;
  width: 500px;
  height: 250px;
  background-color: burlywood;
  border-radius: 15px 15px 15px 15px;
}

.car-count {
  position: absolute;
  margin-top: 20px;
  margin-left: 1000px;
  width: 500px;
  height: 250px;
  background-color: black;
  border-radius: 15px 15px 15px 15px;
}

.car-status {
  position: absolute;
  margin-top: -300px;
  margin-left: 1000px;
  width: 500px;
  height: 300px;
  background-color: #b3c0d1;
  border-radius: 15px 15px 15px 15px;
}

.show-other {
  position: absolute;
  margin-top: -300px;
  margin-left: 510px;
  width: 480px;
  height: 570px;
  background-color: #b3c0d1;
  border-radius: 15px 15px 15px 15px;
}
</style>

需要注意的就是它的CSS了,我写的这个CSS比较拉跨,建议大家自行编写。(CSS永远的痛)

下面是我使用Element UI编写的一个登录界面,看起来好丑(哈哈哈哈)。不过功能还是不错的。


具体实现代码如下:

<template>
  <div class="login-container">
    <div class="login-body">
      欢迎来到车载物联网系统
      <!-- 登录界面头部 -->
      <div class="login-header">用户登录</div>
      <!-- 登录界面表单 -->
      <!-- ref:得到表单实例对象 :model  :相当于v-bind   -->
      <el-form ref="loginFormRef" :model="loginForm" :rules="rules" class="login-form">
        <el-form-item prop="useruame" label="用户名">
          <el-input v-model="loginForm.useruame" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            type="password"
            v-model="loginForm.password"
            autocomplete="off"
            placeholder="请输入密码"
            show-password
          ></el-input>
        </el-form-item>

        <!-- 登录界面按钮 -->
        <el-form-item class="btn">
          <el-button type="primary" @click="onLogin('loginFormRef')">登录</el-button>
          <el-button type="info" @click="resetLoginForm">重置</el-button>
        </el-form-item>
      </el-form>

      <!-- 登录界面其他选项 -->
      <div class="other-option">
        <span @click="onRegister">注册账户</span>
        <span style="margin: 0 30px">|</span>
        <span>找回密码</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //登录表单的数据绑定对象,记得加上:
      loginForm: {
        input: '',
        useruame: '',
        password: '',
      },
      //登录表单的验证规则对象,规则名字要和loginForm的一样
      rules: {
        // 用户名规则
        useruame: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' },
        ],
        // 密码规则
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 8, max: 16, message: '长度在 8 到 16 个字符', trigger: 'blur' },
        ],
      },
    }
  },

  methods: {
    onLogin(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const result = this.$http.post('login', this.loginForm)
          console.log(result)
          var useruame1 = localStorage.userName
          var password1 = localStorage.passWord
          console.log('获得用户名' + useruame1)
          console.log('获得密码' + password1)
          if (useruame1 === this.loginForm.useruame && password1 === this.loginForm.password) {
            this.$alert('', '登录成功', {
              showClose:true,
              showConfirmButton:true,
              callback: (action) => {
                this.$message({
                  type: 'info',
                  message: `action: ${action}`,
                })
              },
            })
            this.$router.replace('/Data')
          } else {
            this.$alert('用户名或密码错误!', '登录失败', {
              confirmButtonText: '确定',
              callback: (action) => {
                this.$message({
                  type: 'info',
                  message: `action: ${action}`,
                })
              },
            })
          }
        } else {
          console.log('error submit!!')
          return false
        }
      })
      console.log(this.loginForm.useruame)
    },
    // 清空表单值
    resetLoginForm() {
      this.$refs.loginFormRef.resetFields()
    },
    //跳转至注册页面
    onRegister() {
      console.log('点击注册用户')
      this.$router.replace('/Register') //默认全局配置$router属性
    },
  },
}
</script>

// scoped只在当前组件生效
<style lang="scss" scoped>
.login-container {
  height: 500px;
  width: 500px;
  background-color: #fff5ee;
  background-image: url('../assets/login.png');
  position: absolute;
  top: 50%;
  left: 50%;
  // 设置div的中心点在我们想要的位置
  transform: translate(-50%, -50%);

  .login-header {
    background-color: #b3c0d1;
    color: #333;
    text-align: center;
    line-height: 60px;
  }

  .login-form {
    color: #3d7ef9;
    width: 300px;
    height: 300px;
    border-radius: 15px 15px 0 0;
    background-color: #fff;
    margin-top: 20px;
    margin-left: 20%;
    padding: 0px 10px; //输入框与登录框两侧的距离
  }
}

.btn {
  display: flex; //弹性布局
  justify-content: center; //置中
}

.other-option {
  display: flex; //弹性布局
  justify-content: center; //置中
  background-color: #fff;
  width: 320px;
  margin-left: 20%;
  margin-bottom: 30x;
}
</style>

如何导入并使用Echars插件

安装与配置基本与Element UI的一样,Echars的官网地址为

https://echarts.apache.org/zh/index.html

安装插件

npm install echarts --save

配置插件(src文件下的main.js)

import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts

使用插件

1 定义界面框的大小


2 编写具体的图形参数

3 效果如下

相关推荐

SpringBoot整合SpringSecurity+JWT

作者|Sans_https://juejin.im/post/5da82f066fb9a04e2a73daec一.说明SpringSecurity是一个用于Java企业级应用程序的安全框架,主要包含...

「计算机毕设」一个精美的JAVA博客系统源码分享

前言大家好,我是程序员it分享师,今天给大家带来一个精美的博客系统源码!可以自己买一个便宜的云服务器,当自己的博客网站,记录一下自己学习的心得。开发技术博客系统源码基于SpringBoot,shiro...

springboot教务管理系统+微信小程序云开发附带源码

今天给大家分享的程序是基于springboot的管理,前端是小程序,系统非常的nice,不管是学习还是毕设都非常的靠谱。本系统主要分为pc端后台管理和微信小程序端,pc端有三个角色:管理员、学生、教师...

SpringBoot+LayUI后台管理系统开发脚手架

源码获取方式:关注,转发之后私信回复【源码】即可免费获取到!项目简介本项目本着避免重复造轮子的原则,建立一套快速开发JavaWEB项目(springboot-mini),能满足大部分后台管理系统基础开...

Spring Boot的Security安全控制——认识SpringSecurity!

SpringBoot的Security安全控制在Web项目开发中,安全控制是非常重要的,不同的人配置不同的权限,这样的系统才安全。最常见的权限框架有Shiro和SpringSecurity。Shi...

前同事2024年接私活已入百万,都是用这几个开源的SpringBoot项目

前言不得不佩服SpringBoot的生态如此强大,今天给大家推荐几款优秀的后台管理系统,小伙伴们再也不用从头到尾撸一个项目了。SmartAdmin...

值得学习的15 个优秀开源的 Spring Boot 学习项目

SpringBoot算是目前Java领域最火的技术栈了,除了书呢?当然就是开源项目了,今天整理15个开源领域非常不错的SpringBoot项目供大家学习,参考。高富帅的路上只能帮你到这里了,...

开发企业官网就用这个基于SpringBoot的CMS系统,真香

前言推荐这个项目是因为使用手册部署手册非常...

2021年超详细的java学习路线总结—纯干货分享

本文整理了java开发的学习路线和相关的学习资源,非常适合零基础入门java的同学,希望大家在学习的时候,能够节省时间。纯干货,良心推荐!第一阶段:Java基础...

jeecg-boot学习总结及使用心得(jeecgboot简单吗)

jeecg-boot学习总结及使用心得1.jeecg-boot是一个真正前后端分离的模版项目,便于二次开发,使用的都是较流行的新技术,后端技术主要有spring-boot2.x、shiro、Myb...

后勤集团原料管理系统springboot+Layui+MybatisPlus+Shiro源代码

本项目为前几天收费帮学妹做的一个项目,JavaEEJSP项目,在工作环境中基本使用不到,但是很多学校把这个当作编程入门的项目来做,故分享出本项目供初学者参考。一、项目描述后勤集团原料管理系统spr...

白卷开源SpringBoot+Vue的前后端分离入门项目

简介白卷是一个简单的前后端分离项目,主要采用Vue.js+SpringBoot技术栈开发。除了用作入门练习,作者还希望该项目可以作为一些常见Web项目的脚手架,帮助大家简化搭建网站的流程。...

Spring Security 自动踢掉前一个登录用户,一个配置搞定

登录成功后,自动踢掉前一个登录用户,松哥第一次见到这个功能,就是在扣扣里边见到的,当时觉得挺好玩的。自己做开发后,也遇到过一模一样的需求,正好最近的SpringSecurity系列正在连载,就结...

收藏起来!这款开源在线考试系统,我爱了

大家好,我是为广大程序员兄弟操碎了心的小编,每天推荐一个小工具/源码,装满你的收藏夹,每天分享一个小技巧,让你轻松节省开发效率,实现不加班不熬夜不掉头发,是我的目标!今天小编推荐一款基于Spr...

Shiro框架:认证和授权原理(shiro权限认证流程)

优质文章,及时送达前言Shiro作为解决权限问题的常用框架,常用于解决认证、授权、加密、会话管理等场景。本文将对Shiro的认证和授权原理进行介绍:Shiro可以做什么?、Shiro是由什么组成的?举...

取消回复欢迎 发表评论: