Vue项目中添加锁屏功能实现思路
1. 实现思路
( 1 ) 设置锁屏密码
( 2 ) 密码存localStorage (本项目已经封装h5的sessionStorage和localStorage)
( 3 ) vuex设置 SET_LOCK state.isLock = true (为true是锁屏状态)
( 4 ) 在路由里面判断vuex里面的isLock(为true锁屏状态不能让用户后退url和自行修改url跳转页面否则可以)
(1)设置锁屏密码
handleSetLock() { this.$refs['form'].validate(valid => { if (valid) { this.$store.commit('SET_LOCK_PASSWD', this.form.passwd) this.handleLock() } }) },
( 2 ) 密码存localStorage setStore是自己封装的方法
SET_LOCK_PASSWD: (state, lockPasswd) => { state.lockPasswd = lockPasswd setStore({ name: 'lockPasswd', content: state.lockPasswd, type: 'session' }) },
( 3 ) vuex设置 SET_LOCK state.isLock = true 同时存在store里面
SET_LOCK: (state, action) => { state.isLock = true setStore({ name: 'isLock', content: state.isLock, type: 'session' }) },
( 4 ) 在路由里面判断vuex里面的isLock
if (store.getters.isLock && to.path !== lockPage) { next({ path: lockPage }) NProgress.done()
总结
相关推荐
sayunara 2020-07-13
81296031 2020-05-08
85206633 2020-02-22
doomvsjing 2012-07-12
huningjun 2012-07-12
berber 2011-02-09
kangtingting0 2010-11-30
gongzhiyao0 2011-04-24
learningITwell 2012-04-26
一柯 2017-07-23
AxDoctor 2017-04-12
asweee 2017-01-16
81236432 2016-08-06
zhouboxiao 2016-06-11
火影忍者 2016-02-24
KLinuxManBlog 2016-01-24
ChanYao 2016-01-21