• element ui框架(登录窗口)


    【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】

            前面说到了路由,有了这个功能,其实后面的工作就比较好开展了。一般来说,很多网页项目都是这样的,首先进入的是登录窗口,在输入用户名和密码之后,就可以进入主页面了。所以,登陆页面本身也是非常重要的一个环节。

            窗口编写的过程中涉及到node-sass、sass-loader的安装,这是因为涉及到css的编写,这部分需要注意下。

    1、创建登录工程,注意选中router功能

    vue init ./webpack login

    2、安装element ui

    1. cd login
    2. npm install element-ui -S

    3、安装其他node_modules,并执行

    1. npm install
    2. npm run dev

    4、将element ui添加到项目中

    1. // The Vue build version to load with the `import` command
    2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
    3. import Vue from 'vue'
    4. import App from './App'
    5. import router from './router'
    6. import ElementUI from 'element-ui';
    7. import 'element-ui/lib/theme-chalk/index.css';
    8. Vue.use(ElementUI);
    9. Vue.config.productionTip = false
    10. /* eslint-disable no-new */
    11. new Vue({
    12. el: '#app',
    13. router,
    14. components: { App },
    15. template: '',
    16. render:h=>h(App)
    17. })

    5、删除原来HelloWorld相关的功能

    5.1 删除App.vue中图片的内容、删除样式

    1. <template>
    2. <div id="app">
    3. <router-view/>
    4. </div>
    5. </template>
    6. <script>
    7. export default {
    8. name: 'App'
    9. }
    10. </script>
    11. <style>
    12. </style>

    5.2 删除HelloWorld.vue中显示的内容,仅保留一个基本框架

    1. <template>
    2. </template>
    3. <script>
    4. export default {
    5. name: 'HelloWorld'
    6. }
    7. </script>
    8. <!-- Add "scoped" attribute to limit CSS to this component only -->
    9. <style scoped>
    10. </style>

    6、创建view目录

    6.1 添加Login.vue

    1. <template>
    2. <div>Login</div>
    3. </template>
    4. <script>
    5. export default {
    6. name: "Login"
    7. }
    8. </script>
    9. <style scoped>
    10. </style>

    6.2 添加Main.vue,其实和Login.vue差不多

    1. <template>
    2. <div>Main</div>
    3. </template>
    4. <script>
    5. export default {
    6. name: "Main"
    7. }
    8. </script>
    9. <style scoped>
    10. </style>

    6.3 修改router/index.js,将Login和Main插入到路由表

    1. import Vue from 'vue'
    2. import Router from 'vue-router'
    3. import HelloWorld from '@/components/HelloWorld'
    4. import Login from '@/view/Login'
    5. import Main from '@/view/Main'
    6. Vue.use(Router)
    7. export default new Router({
    8. routes: [
    9. {
    10. path: '/',
    11. name: 'HelloWorld',
    12. component: HelloWorld
    13. },
    14. {
    15. path: '/Login',
    16. name: 'Login',
    17. component: Login
    18. },
    19. {
    20. path: '/Main',
    21. name: 'Main',
    22. component: Main
    23. }
    24. ]
    25. })

    6.4 输入127.0.0.1:8082/#/Login和127.0.0.1:8082/#/Main来进行验证。

    7、准备利用element ui组件来修饰Login.vue

    7.1 因为编写的过程中涉及到style的编写,所以需要安装node-sass、sass-loader

    1. npm install node-sass@4.13.1 --registry=http://registry.npm.taobao.org
    2. npm install sass-loader@7.3.1 --registry=http://registry.npm.taobao.org

    7.2 修改Login.vue

    1. <template>
    2. <div>
    3. <el-form ref="form" :model="form" :rules="rules" class="login-box">
    4. <h3 class="login-title">欢迎登陆</h3>
    5. <el-form-item label="姓名" prop="name">
    6. <el-input v-model="form.name"></el-input>
    7. </el-form-item>
    8. <el-form-item label="密码" prop="password">
    9. <el-input v-model="form.password"></el-input>
    10. </el-form-item>
    11. <el-form-item>
    12. <el-button type="primary" @click="submitForm('form')">确定</el-button>
    13. <el-button>取消</el-button>
    14. </el-form-item>
    15. </el-form>
    16. </div>
    17. </template>
    18. <script>
    19. export default {
    20. name: "Login",
    21. data() {
    22. return {
    23. form:{
    24. name:'',
    25. password:''
    26. },
    27. rules:{
    28. name: [
    29. { required: true, message: '请输入姓名', trigger: 'blur' },
    30. ],
    31. password: [
    32. { required: true, message: '请选择密码', trigger: 'change' }
    33. ]
    34. }
    35. }
    36. },
    37. methods:{
    38. submitForm(formName) {
    39. //alert('submit!');
    40. this.$refs[formName].validate((valid) => {
    41. if (valid) {
    42. this.$router.push("/Main");
    43. } else {
    44. this.$message.error('请输入正确用户名或密码!');
    45. return false;
    46. }
    47. });
    48. }
    49. }
    50. }
    51. </script>
    52. <style lang="scss" scoped>
    53. .login-box{
    54. width: 350px;
    55. margin:120px auto;
    56. border:1px solid #DCDFE6;
    57. padding:20px;
    58. border-radius:5px;
    59. box-shadow:0 0 30px #DCDFE6;
    60. }
    61. .login-title{
    62. text-align: center;
    63. }
    64. </style>

    8、测试网页

            有了上面这些操作,在npm run dev运行后,就可以看到不错的登录框效果了,

  • 相关阅读:
    终于更新了!时隔一年niushop多商户b2b2c的新补丁v5.0.2终于发布了,一起看看有啥新变化
    阿里云99 / 腾讯云88,现在服务器这么便宜了吗?价格降这么多
    周星驰亲自下场招人 Web3.0究竟是什么?
    spring中基础核心接口总结
    mvc基于ASP NET大学生校园招聘网站的C#设计与开发
    R语言机器学习之caret包详解
    windows 设置nginx、redis、jar包开机自启、mysql自动备份
    「PAT乙级真题解析」Basic Level 1005 继续(3n+1)猜想 (问题分析+完整步骤+伪代码描述+提交通过代码)
    数据结构——线性表之顺序表的基本操作讲解
    【2023秋招面经】4399 前端 一面-部门初面(26min)
  • 原文地址:https://blog.csdn.net/feixiaoxing/article/details/126915737