1.src/router/index.js中进行路由设置,代码如下
import Vue from 'vue' import Router from "vue-router"; Vue.use(Router); import Login from "@/views/Login/login" const routes = [ //匹配空路由跳转到登录页 { path: '', redirect: "/login",//重定向 }, //登录 { path: '/login', name: 'login', component: Login, } ] const router = new Router({ mode: 'history', routes }) export default router
1.创建 src/views/Login/login.vue文件
2.在网上或者本地随便找一找图片,当做登录页背景图,在login.vue中引入
src/views/Login目录下login.vue的代码如下
此时,在浏览器网址栏输入 localhost://[你的端口号,默认是8080],会自动跳转到login页面
就可以看到引入的背景图
3.创建src/views/Login/index.vue文件,为登录组件
以下是index.vue代码
账号登录 忘记密码没有账号?点我立即注册 登录 4.在login.vue中进行引入注册 index.vue,并在页面上展示
login.vue中添加以下代码
template中展示
添加样式
走到这一步,页面上应该可以看到效果了
但也只是有 页面效果而已,实际功能并未完善
1.json-server模拟后端数据
因为登录,注册,验证码这些功能都需要后端支持,所以需要模拟后台数据,我个人喜欢用json-server
可以直接在项目目录下,进入cmd命令行,输入 npm i json-server --save 进行安装
随便在哪个地方创建一个data.json文件,甚至在电脑桌面也行
data.json中写入以下代码
{ "userList": [ { "userName": "123", "passward": "123", "id": 1 }, { "userName": "admin", "password": "admin", "id": 2 } ], "validateCode":[ { "id":1, "img":"/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAaAEYDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RF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0+6evaXw3O3kXcPkxSpEpndZbyaJSgGGyqKyuOmQR+Y6Er2uhre1zrr/wAV2Gn6k9hNFOZUKgsAgXkAjksMde9SS+KNNjW32/aZHuSot0+zunm5IA2lwF7jnNeXkC+1SGMwkJcTgGK3wvBb7qZOB1wM8dK7vxDq1jbaQsWp6ZfWECFWieOS2V4ypGDGBITxkDgcA1lJu7S6FpK12N8Xazf6fY219b2T2sqTGMSTshJDI3ACscjgHkgZVeD2wrO58Wa1Ym4ishcpJlPOeZkVu3+r8wIR2+7g4Oc81b1LU7LxtaJFbajIIophI8UGnzTNECrAbyqnLH0BAHzctgGsW9fU/C5tzp+sXjQDIVJoJIACc5xHIMMOc5GcE84JGcpcyd9bGsI3W2vmepabE0OmWyPbxW0nlgyQwqAiORlgAOOpNFVtA1ePW9GgvVK+YRtlVf4HHUYyceozzgiiuhO6MWrMn1a0kv8ARr6ziKiSe3kiUseAWUgZ9ua83sfDHijwt5gs9Y063e5xmNQ0rybc/dXyyTjcc4H1r1So0ghjmkmSJFllx5jqoDPjgZPfFUmS1c840zwDql/qw1TXrhTIzFpUkVZCzZ4xg7duMYzwCMFSvXP17TJdK1aaCTbtYmSNhjlCTg4AAB46YA444xXrdFHMFkjy06QZdAtLq0tPt91FP5s0aIsiBDgCNwDlj8oO0dAxyBkZ6W2k0+xsltfC7W0t/dushZI0ACgjJlCgBFC8YwDk8DJJrq440ijWONFREAVVUYAA6ACnVlytu99xp6K5ja9/byfZ59E8iTy93nW8uP3ucBcHjpyeo/HpXJarpPjHxLNDFfW0FrAmSAsoEYbn5iAzEnt7e2TXo1FEoc27LjPl2RT0nTo9J0q2sYjlYUwW5+ZupPU4ySTj3oq5RVpW0Jbuf//Z", "code":"DVC5" } ] }
userList为用户列表,validateCode为验证码,这里是写死的一些数据
直接在你的data.json文件所在目录下cmd进入命令行
输入 json-server data.json
如果出现了这个
就说明json-server服务启动了,可以正常访问
在浏览器网址栏输入其中的地址
2,配置axios请求
项目目录下安装axios, npm i axios --save
安装成功之后,在src/utils目录下新建request.js文件
代码如下
import axios from "axios"; const HTTP = axios.create({ "baseURL": "http://localhost:3000/",//请求url公共部分 , 3000为端口号 "timeout": 3000,//超时时间 }) //请求拦截器 HTTP.interceptors.request.use(config => { //请求头添加token const token = "token" config.headers = Object.assign(config.headers, { token }) return config }) //响应拦截器 HTTP.interceptors.response.use(res => { //请求头添加token return new Promise((resolve, reject) => { if (res.status >= 200 || res.status < 300) { // 添加code码 resolve({ data: res.data, code: 0 }) } else { reject({code : 2 , error :"系统错误,请稍后再试"}) } }) }) export default HTTP
3,接口配置
在src/api目录下新建servers.js文件
代码如下
import request from "@/utils/request" //登录 export function login(params) { return request({ url: "/userList", method: "get", data: params }) } //刷新验证码 export function getValidateCode() { //随机ID 1-10 let id = Math.floor(Math.random() * (10)) + 1; return request({ url: `/validateCode?id=${id}`, method: "GET" }) }
4,页面中引入接口,并发送获取验证码请求
在src/views/Login/index.vue中引入:srcipt标签中 第一行添加以下代码
import { login, getValidateCode} from "@/api/servers";
methods中添加页面加载状态事件
methods: { //设置页面加载状态 setLoading(bool) { this.loading = bool },
created生命周期中进行网络请求,获取验证码
created() { this.setLoading(true) //setTimeout模拟网络延迟 setTimeout(() => { //接口调用 getValidateCode().then((res) => { this.codeURL = `data:image/png;base64,${res.data[0].img}`; }); this.setLoading(false) }, 500) },
有不太清楚的可以console.log(res)以下,看模拟后台返回的是什么数据
给codeURL赋值这一步,不懂的可以看看base64编码解码相关的内容
到这一步,每次刷新页面,就可以随机刷新一个图形验证码
给包裹这个img的div标签绑定一个点击事件
点击验证码可以再次刷新,所以代码需要优化一下
效果
5,给登录按钮绑定点击事件,并进行登录验证
登录 login() { this.$refs.loginForm.validate((val) => { if (val) { this.setLoading(true) setTimeout(() => { const { userName, password, validateCode } = this.loginForm; //验证码效验 verifyCode(validateCode).then((res) => { console.log(res); if (res.data.length !== 0) { //用户名密码效验 login({ userName, password }).then((res2) => { if (res2.data.some(item => item.userName === userName && item.password === password)) { this.$router.push("/home"); } else { this.errorMessage("用户名或密码错误,请重试") } setTimeout(() => { this.setLoading(false) } , 200) }); } else { this.errorMessage("验证码错误") } console.log(res); }); }, 500); } }); }, errorMessage(message) { this.validateCode() this.$message({ message, type: "error", center:true }); this.$refs.loginForm.resetFields(); },
至此,登录功能已完成
完结撒花----------------------------------------------------------------------------------------------------------------------------------------------------!!!