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

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

ztj100 2024-12-03 06:54 67 浏览 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 效果如下

相关推荐

Win10预览版10532已知问题汇总(微软win11正式版已知问题一览)

IT之家讯微软已向Insider用户推送了Win10预览版10532更新,本次更新对右键菜单、《Windows反馈》应用以及Edge浏览器进行了改进。除此之外还包含一些Bug,汇总如下,有意升级Wi...

Gabe Aul正测试Win10 Mobile 10532,Insider用户还需等

IT之家讯本月中旬微软向Insider用户推送了Win10Mobile预览版10512,该版本修复了一些Bug,增强了系统稳定性,但依然存在一些问题。今天,微软Insider项目负责人GabeAu...

微软开始推送Win10预览版10532快速版更新

8月28日消息,刚才,微软推送了Win10Build10532快速版,修复了之前的Bug,并带来了三项改进。主要来说,这次的更新改进了右键菜单的UI,使其更具Modern风格(见上图)。此外,更新...

Win10预览版10532更新内容大全(windows10更新预览版)

IT之家讯今天凌晨微软向Insider用户推送了Win10预览版10532快速版更新,本次更新主要带来了三处改进,汇总如下:o改进右键菜单,外观更加Modern。这是基于网友要求界面一致的反馈做出...

无法升级Win10预览版10532?也许Hyper-V在搞鬼

根据IT之家网友的反映,安装了微软虚拟机Hyper-V的Win10预览版用户无法成功升级Build10532版本,安装过程中会被要求回滚系统。很多朋友在尝试关闭虚拟机之后重启安装程序,结果仍然无法顺...

Win10预览版10532界面兴起“酷黑”风潮

Win10预览版10532的界面改动还是较为明显的,主要体现在右键菜单上面。总体来看,该版本的右键菜单间距更宽,视觉上更大气,操作上更便于触控。具体来说,任务栏右键菜单的变化最为明显。除了增加选项的宽...

Win10预览版10532上手图集(windows10预览版下载)

IT之家讯8月28日,微软今天推送了Win10预览版10532快速版更新,在该版本中,微软主要是加强细节上调整,并且主要是增强Edge浏览器性能等。在Windows10预览版10532中,微软改进了...

Win10预览版10532上手视频亮点演示

IT之家讯8月28日消息,今天凌晨微软向WindowsInsider快速通道用户推送了Win10预览版10532。在Windows10预览版10532中,微软改进了右键菜单,外观更加现代化。另外还...

第二篇 前端框架Vue.js(vue前端框架技术)

前端三大核心是网页开发的基础,Vue则是基于它们构建的“生产力工具”。通俗理解就是HTML是化妆的工具如眉笔,CSS是化妆品如口红,JavaScript是化妆后的互动,而Vue就是化妆助手。有了化妆工...

基于SpringBoot + vue2实现的旅游推荐管理系统

项目描述...

基于Vue以及iView组件的后端管理UI模板——iview-admin

介绍iView-admin是一套后端管理界面模板,基于Vue2.0,iView(现在为ViewUI)组件是一套完整的基于Vue的高质量组件库,虽然Github上有一套非常火的基于ElementUI...

别再说你会SPA开发了,这5个核心你真的搞懂了吗?

前言此spa非彼spa,不是你所熟知的spa。你所熟知的spa作者肯定是没有你熟悉的。我们这里指的是在前端开发中的一种模型,叫作单页应用程序,顾名思义,就是整个项目只有一个页面,而页面中的内容是动态的...

React.js Top20面试题(react.js中文官网)

概述作为React开发者,对框架的关键概念和原则有扎实的理解是很重要的。考虑到这一点,我整理了一份包含20个重要问题的清单,每个React开发者都应该知道,无论他们是在面试工作还是只是想提高技能。...

美媒:特朗普签署行政令后,FBI又发现约2400份、总计超14000页涉肯尼迪遇刺案文件

来源:环球时报新媒体1月23日特朗普下令公布肯尼迪遇刺案相关机密文件图源:美媒综合福克斯新闻网和Axios网站10日报道,在总统特朗普签署行政令,要求公布“肯尼迪遇刺案”相关政府机密文件之后,美国...

2021 年 Node.js 开发人员学习路线图

Node.js自发布以来,已成为业界重要破局者之一。Uber、Medium、PayPal和沃尔玛等大型企业,纷纷将技术栈转向Node.js。Node.js支持开发功能强大的应用,例如实时追踪...

取消回复欢迎 发表评论: