vue结合element-ui美化登录页面

1---最终效果

2--引入element-ui:

在项目文件夹下,执行 npm i element-ui -S 即可

3--修改main.js内容:

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

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

// 设置反向代理,前端请求默认发送到 http://localhost:8443/api
var axios=require('axios')
axios.defaults.baseURL='http://localhost:8443/api'
Vue.prototype.$axios = axios
Vue.config.productionTip = false
/*作用是阻止vue 在启动时生成生产提示。*/

Vue.use(ElementUI)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  render: h=>h(App),
  router,                /*router 代表该对象包含 Vue Router,并使用项目中的路由*/
  components: { App },   /*components 表示该对象包含的 Vue 组件,*/
  template: '<App/>'     /*template 是用一个字符串模板作为 Vue 实例的标识使用,类似于定义一个 html 标签*/
})

4---使用form组件 美化:

其中添加body组件,引入背景图片,选一张自己喜欢的就好!

<template>
  <body id="poster">
    <el-form class="login-container" label-position="left" label-width="0px">
      <h3 class="login_title">系统登录</h3>
      <el-form-item>
        <el-input type="text" v-model="loginForm.username" auto-complete="off" placeholder="账号"></el-input>
      </el-form-item>

      <el-form-item>
        <el-input type="password" v-model="loginForm.password" auto-complete="off" placeholder="密码"></el-input>
      </el-form-item>

      <el-form-item style="width: 100%">
        <el-button type="primary" style="width: 100%;background: #505458;border: none" v-on:click="login">登录</el-button>
      </el-form-item>
    </el-form>
  </body>
</template>


<script>
    export default {
        name: "Login",
        data() {
            return {
                loginForm: {
                    username: '',
                    password: ''
                },
                responseResult: []
            }
        },
        methods: {
            login() {
                this.$axios
                    .post('/login', {
                        username: this.loginForm.username,
                        password: this.loginForm.password
                    })
                    .then(successResponse => {
                        if (successResponse.data.code === 200) {
                            this.$router.replace({path: '/index'})
                        }
                    })
                    .catch(failResponse => {
                    })
            }
        }
    }
</script>

<style>
  #poster {
    background:url("../assets/eva.jpg") no-repeat;
    background-position: center;
    height: 100%;
    width: 100%;
    background-size: cover;
    position: fixed;
  }
  body{
    margin: 0px;
    padding: 0;
  }

  .login-container {
    border-radius: 15px;
    background-clip: padding-box;
    margin: 90px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }

  .login_title {
    margin: 0px auto 40px auto;
    text-align: center;
    color: #505458;
  }


</style>

 

 

  • 8
    点赞
  • 79
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Vue.js是一款流行的JavaScript框架,它的灵活性和易用性使其成为构建用户界面的首选工具。Element-UI则是一个基于Vue.js的一套桌面端UI组件库,它提供了丰富的UI组件,使得搭建管理后台变得更加简单。 要使用Element-UI搭建管理后台,首先需要在Vue项目中安装Element-UI。可以通过npm或者yarn命令来安装,具体的安装命令可以在官方文档中找到。 安装完成后,在项目中引入Element-UI。可以在main.js文件中添加以下代码来全局引入Element-UI的样式和组件: ``` import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; Vue.use(ElementUI); ``` 接下来就可以在Vue组件中使用Element-UI的组件了。例如,可以在组件的模板中添加一个按钮: ``` <el-button>点击我</el-button> ``` 使用Element-UI的组件和样式,可以轻松实现页面的布局和美化。其中包括菜单、表格、表单、弹窗等各种常用的管理后台组件。 Element-UI还提供了丰富的交互和功能组件,例如消息提示、弹窗确认框、分页等。可以根据具体需求在组件中使用这些功能。 在搭建管理后台时,还可以利用Element-UI的路由和菜单组件来实现页面的导航。可以通过路由配置文件来定义不同页面的路由路径,然后在菜单组件中使用路由链接来跳转到不同的页面。 总之,使用Element-UI搭建管理后台是非常简单和高效的。通过引入Element-UI的样式和组件,可以快速搭建出功能丰富、界面美观的管理后台。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值