使用font-awesomecss
npm install --save font-awesome
修改 src/main.js 增長vue
import 'font-awesome/scss/font-awesome.scss'
效果以下
修改原來的用戶輸入框npm
<template slot="prepend"><span class="fa fa-user fa-lg" style="width: 13px"></span></template>
和密碼輸入框bash
<template slot="prepend"><span class="fa fa-lock fa-lg" style="width: 13px"></span></template> <template slot="suffix"><span class="password-eye" @click="showPassword" :class="eyeType"></span></template>
給"眼睛"增長click事件cookie
/** ... */ pwdType: 'password', eyeType: 'fa fa-eye-slash fa-lg' /** ... */ showPassword() { if (this.pwdType === 'password') { this.pwdType = '' this.eyeType = 'fa fa-eye fa-lg' } else { this.pwdType = 'password' this.eyeType = 'fa fa-eye-slash fa-lg' } }
成功登錄後把用戶名和密碼存入cookie,再次進入頁面時讀取cookiethis
/** ... */ setCookie(name, pass, days){ let expire = new Date() expire.setDate(expire.getDate() + days) document.cookie = `C-username=${name};expires=${expire}` document.cookie = `C-password=${pass};expires=${expire}` }, getCookie(){ if(document.cookie.length){ let arr = document.cookie.split('; ') for(let i=0; i<arr.length; i++){ let arr2 = arr[i].split('=') if(arr2[0] === 'C-username'){ this.ruleForm2.username = arr2[1] }else if(arr2[0] === 'C-password'){ this.ruleForm2.password = arr2[1] this.rememberme = true } } } }, // 修改成空,天數爲-1 deleteCookie(){ this.setCookie('', '', -1); } /** ... */ // 登錄成功 保存賬號密碼 if(this.rememberme){ this.setCookie(this.ruleForm2.username, this.ruleForm2.password, 7) }else{ this.deleteCookie() } /** ... */ // 頁面載入後讀取cookie mounted(){ this.getCookie() }