使用Vue写一个登录页面

作者 : admin 本文共3795个字,预计阅读时间需要10分钟 发布时间: 共26人阅读

上一博客讲到构建了一个vue项目,现在在那个项目之上实现一个登录页面。

1.构建项目的目录

使用Vue写一个登录页面插图

2.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>

 

main.js

  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. //自己写的样式
  9. import ‘./style/theme.css’
  10. import ‘./style/characters.css’
  11. // 注册element-ui
  12. Vue.use(ElementUI)
  13. Vue.config.productionTip = false
  14. /* eslint-disable no-new */
  15. new Vue({
  16. el: ‘#app’,
  17. router,
  18. components: { App },
  19. template: ‘<App/>’
  20. })

 

theme.css

  1. body {
  2. padding: 0;
  3. margin:0;
  4. font-family: “Microsoft YaHei UI Light”;
  5. }
  6. .outer_label {
  7. position: relative;
  8. left: 0;
  9. top: 0;
  10. width: 100%;
  11. height: 220px;
  12. background: -webkit-linear-gradient(left, #000099, #2154FA); /* Safari 5.1 – 6.0 */
  13. background: -o-linear-gradient(right, #000099, #2154FA); /* Opera 11.1 – 12.0 */
  14. background: -moz-linear-gradient(right, #000099, #2154FA); /* Firefox 3.6 – 15 */
  15. background: linear-gradient(to right, #000099 , #2154FA); /* 标准的语法 */
  16. /*background-color: #000099;*/
  17. text-align: center;
  18. filter: brightness(1.4);
  19. }
  20. .inner_label {
  21. position: absolute;
  22. left:0;
  23. right: 0;
  24. bottom: 0;
  25. top:0;
  26. margin: auto;
  27. height: 50px;
  28. }
  29. .qxs-icon {
  30. height: 40px;
  31. width: 90%;
  32. margin-bottom: 5px;
  33. padding-left: 10%;
  34. border: 0;
  35. border-bottom: solid 1px lavender;
  36. }

 

character.css

  1. .text-size12px{
  2. font-size: 12px;
  3. }
  4. .text-size14px{
  5. font-size: 14px;
  6. }
  7. .text-size16px{
  8. font-size: 16px;
  9. }
  10. .float-right {
  11. float: right;
  12. }
  13. .item-color {
  14. color: #848487;
  15. }

 

index.js

  1. import Vue from ‘vue’
  2. import Router from ‘vue-router’
  3. // import HelloWorld from ‘@/components/HelloWorld’
  4. import Login from ‘@/components/login/Login’
  5. Vue.use(Router)
  6. export default new Router({
  7. routes: [
  8. {
  9. path: ‘/’,
  10. name: ‘Login’,
  11. component: Login
  12. }
  13. ]
  14. })

 

Login.vue

  1. <template>
  2. <div>
  3. <div class=“outer_label”>
  4. <img class=“inner_label login_logo” src=“../../assets/logo.png”>
  5. </div>
  6. <div class=“login_form”>
  7. <input type=“text” class=“qxs-ic_user qxs-icon” placeholder=“用户名” v-model=“userName”>
  8. <input type=“text” class=“qxs-ic_password qxs-icon” placeholder=“密码” v-model=“password”>
  9. <!–<button class=”login_btn el-button el-button&#45;&#45;primary is-round” type=”primary” round>登录</button>–>
  10. <el-button class=“login_btn” @click.native=“login” type=“primary” round :loading=“isBtnLoading”>登录</el-button>
  11. <div style=“margin-top: 10px”>
  12. <span style=“color: #000099;” @click=“login”>司机账号登陆</span><span style=“float: right;color: #A9A9AB”>忘记密码?</span>
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. // import { userLogin } from ‘../../api/api’;
  19. export default {
  20. data() {
  21. return {
  22. userName: ,
  23. password: ,
  24. isBtnLoading: false
  25. }
  26. },
  27. created () {
  28. if(JSON.parse( localStorage.getItem(‘user’)) && JSON.parse( localStorage.getItem(‘user’)).userName){
  29. this.userName = JSON.parse( localStorage.getItem(‘user’)).userName;
  30. this.password = JSON.parse( localStorage.getItem(‘user’)).password;
  31. }
  32. },
  33. computed: {
  34. btnText() {
  35. if (this.isBtnLoading) return ‘登录中…’;
  36. return ‘登录’;
  37. }
  38. },
  39. methods: {
  40. login() {
  41. if (!this.userName) {
  42. this.$message.error(‘请输入用户名’);
  43. return;
  44. }
  45. if (!this.password) {
  46. this.$message.error(‘请输入密码’);
  47. return;
  48. }
  49. }
  50. }
  51. }
  52. </script>
  53. <style>
  54. .login_form {
  55. padding-top: 10%;
  56. padding-left: 10%;
  57. padding-right: 10%;
  58. }
  59. .qxs-ic_user {
  60. background: url(“../../assets/login/ic_user.png”) no-repeat;
  61. background-size: 13px 15px;
  62. background-position: 3%;
  63. }
  64. .qxs-ic_password {
  65. background: url(“../../assets/login/ic_password.png”) no-repeat;
  66. background-size: 13px 15px;
  67. background-position: 3%;
  68. margin-bottom: 20px;
  69. }
  70. .login_logo {
  71. height: 100%;
  72. }
  73. .login_btn {
  74. width: 100%;
  75. font-size: 16px;
  76. background: -webkit-linear-gradient(left, #000099, #2154FA); /* Safari 5.1 – 6.0 */
  77. background: -o-linear-gradient(right, #000099, #2154FA); /* Opera 11.1 – 12.0 */
  78. background: -moz-linear-gradient(right, #000099, #2154FA); /* Firefox 3.6 – 15 */
  79. background: linear-gradient(to right, #000099 , #2154FA); /* 标准的语法 */
  80. filter: brightness(1.4);
  81. }
  82. </style>

 

ic_password.png

使用Vue写一个登录页面插图(1)

ic_user.png

使用Vue写一个登录页面插图(2)

logo.png

使用Vue写一个登录页面插图(3)

 

3.根据npm run dev 命令启动,启动完成之后会有个链接,访问链接就直接可以看到下面页面:

使用Vue写一个登录页面插图(4)

 

问题交流群,不定期分享各种技术文档:

QQ群号:464512055

群二维码:

使用Vue写一个登录页面插图(5)

这是一个神器的二维码,扫描之后你会少掉一块钱。

使用Vue写一个登录页面插图(6)

 


滴石it网-Java学习中高级和架构师教程_Java企业级开发项目实战下载 » 使用Vue写一个登录页面

常见问题FAQ

发表回复

开通VIP 享更多特权,建议使用QQ登录