最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue+element實(shí)現(xiàn)輸入密碼鎖屏

 更新時(shí)間:2022年03月07日 13:58:36   作者:小聰聰???  
這篇文章主要為大家詳細(xì)介紹了vue+element實(shí)現(xiàn)輸入密碼鎖屏,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue+element實(shí)現(xiàn)輸入密碼鎖屏的具體代碼,供大家參考,具體內(nèi)容如下

1.頁(yè)面中個(gè)的點(diǎn)擊事件

通過vuex來存在狀態(tài)

/**
? * 鎖屏功能
? */
?? ??? ??? ?lock() {
?? ??? ??? ??? ?console.log('鎖屏')
?? ??? ??? ??? ?const that = this
?? ??? ??? ??? ?this.$prompt('請(qǐng)輸入鎖屏密碼', '提示', {
?? ??? ??? ??? ??? ?confirmButtonText: '確定',
?? ??? ??? ??? ??? ?cancelButtonText: '取消',
?? ??? ??? ??? ??? ?inputPattern: /\S/, ? ?? ? //判斷不為空正則
?? ??? ??? ??? ??? ?inputErrorMessage: '鎖屏密碼不能為空'
?? ??? ??? ??? ?}).then(({
?? ??? ??? ??? ??? ?value
?? ??? ??? ??? ?}) => {
?? ??? ??? ??? ??? ?that.isLock = !that.isLock
?? ??? ??? ??? ??? ?that.$store.commit('SET_LOCK_PASSWD', value)
?? ??? ??? ??? ??? ?that.elementTips("success", "鎖屏成功");
?? ??? ??? ??? ??? ?this.handleLock()
?? ??? ??? ??? ?}).catch(() => {
?? ??? ??? ??? ??? ?that.elementTips("info", "鎖屏失敗");
?? ??? ??? ??? ?});
?? ??? ??? ?},
?? ??? ??? ?//判斷輸入框是否有內(nèi)容,有內(nèi)容就跳轉(zhuǎn),設(shè)置狀態(tài)
?? ??? ??? ?handleLock() {
?? ??? ??? ??? ?const that = this
?? ??? ??? ??? ?if (util.validatenull(this.lockPasswd)) {
?? ??? ??? ??? ??? ?this.box = true
?? ??? ??? ??? ??? ?return
?? ??? ??? ??? ?}
?? ??? ??? ??? ?that.$store.commit('SET_LOCK')
?? ??? ??? ??? ?setTimeout(() => {
?? ??? ??? ??? ??? ?that.go('/lock')
? ? ? ? ? }, 100)
?},

2.在vuex中設(shè)置狀態(tài)

import util from '@/utils'
import store from '../'
import cookie from '@/utils/cookie.js'
const mutations = {
?? ?SET_IM(state, userInfo) {
?? ??? ?console.log('user:', userInfo)
?? ??? ?state.userInfo = userInfo
?? ?},
?? ?SET_LOCK(state, action) {
?? ??? ?state.isLock = true
?? ??? ?util.setStore('isLock', state.isLock)

?? ??? ?// console.log('util.setStore',util.getStore('isLock'))
?? ?},
?? ?SET_LOCK_PASSWD(state, lockPasswd) {
?? ??? ?state.lockPasswd = lockPasswd
?? ??? ?util.setStore('lockPasswd', state.lockPasswd)

?? ??? ?// console.log('util.setStore',util.getStore('lockPasswd'))
?? ?},
?? ?CLEAR_LOCK(state, action) {
?? ??? ?state.isLock = false
?? ??? ?state.lockPasswd = ''
?? ??? ?util.removeStore('lockPasswd')
?? ??? ?util.removeStore('isLock')
?? ??? ?// console.log('state.isLock',state.isLock)
?? ?},
?? ?}
export default mutations


/**
?*?
?* @author getters?
?*/
const getters = {
? isLock: state => state.isLock,
? lockPasswd: state => state.lockPasswd,
}
export default getters


/**
?* @desc 狀態(tài)表
?* @author Vman?
?* @time 2019/9/6
?*/
import {
?? ?getStore
} from '@/utils'
export default {
?? ?userInfo: {},
?? ?//im 實(shí)例
?? ?nim: null,
?? ?name: '',
?? ?isLock: false,
?? ?lockPasswd: '',
?? ? userUID: '',
?? ?sdktoken: '',
}

3.解鎖頁(yè)面

<template>
?? ?<div class="lock-container pull-height">
?? ??? ?<div class="lock-form animated bounceInDown">
?? ??? ??? ?<div class="animated" :class="{'shake':passwdError,'bounceOut':pass}">
?? ??? ??? ??? ?<h3 class="text-white">{{name}}</h3>
?? ??? ??? ??? ?<el-input placeholder="請(qǐng)輸入登錄密碼" type="password" class="input-with-select animated" v-model="passwd"
?? ??? ??? ??? ? @keyup.enter.native="handleLogin">
?? ??? ??? ??? ??? ?<!-- <el-button slot="append" @click="handleLogin" style="padding-right:36px;"><svg-icon ?class-name='international-icon' icon-class="deblocking"/></el-button> -->
?? ??? ??? ??? ??? ?<!-- <el-button slot="append" @click="handleLogout"><svg-icon class-name='international-icon' icon-class="lockOut"/></el-button> -->
?? ??? ??? ??? ??? ?<el-button slot="append" @click="handleLogin" style="padding-right:36px;"><i class="el-icon-unlock"></i></el-button>
?? ??? ??? ??? ??? ?<el-button slot="append" @click="handleLogout"><i class="el-icon-switch-button"></i></el-button>
?? ??? ??? ??? ?</el-input>
?? ??? ??? ?</div>
?? ??? ?</div>
?? ?</div>
</template>
<script>
?? ?import util from '@/utils'
?? ?import {
?? ??? ?mapGetters,
?? ??? ?mapState
?? ?} from 'vuex'
?? ?export default {
?? ??? ?name: 'lock',
?? ??? ?data() {
?? ??? ??? ?return {
?? ??? ??? ??? ?passwd: '',
?? ??? ??? ??? ?passwdError: false,
?? ??? ??? ??? ?pass: false
?? ??? ??? ?}
?? ??? ?},
?? ??? ?created() {},
?? ??? ?mounted() {},
?? ??? ?computed: {
?? ??? ??? ?...mapState({
?? ??? ??? ??? ?name: state => state.name
?? ??? ??? ?}),
?? ??? ??? ?...mapGetters(['tag', 'lockPasswd'])
?? ??? ?},
?? ??? ?props: [],
?? ??? ?methods: {
?? ??? ??? ?handleLogout() {
?? ??? ??? ??? ?this.$confirm('是否退出系統(tǒng), 是否繼續(xù)?', '提示', {
?? ??? ??? ??? ??? ?confirmButtonText: '確定',
?? ??? ??? ??? ??? ?cancelButtonText: '取消',
?? ??? ??? ??? ??? ?type: 'warning'
?? ??? ??? ??? ?}).then(() => {
?? ??? ??? ??? ??? ?//刪除vuex狀態(tài)表
?? ??? ??? ??? ??? ?this.$store.commit('CLEAR_LOCK')
?? ??? ??? ??? ??? ?//刪除user_token
?? ??? ??? ??? ??? ?util.removeStore('user_token')
?? ??? ??? ??? ??? ?this.$router.push({
?? ??? ??? ??? ??? ??? ?path: '/login'
?? ??? ??? ??? ??? ?})
?? ??? ??? ??? ??? ?console.log('555')
?? ??? ??? ??? ?}).catch(() => {
?? ??? ??? ??? ??? ?return false
?? ??? ??? ??? ?})
?? ??? ??? ?},
?? ??? ??? ?handleLogin() {
?? ??? ??? ??? ?console.log('this.lockPasswd', this.lockPasswd)
?? ??? ??? ??? ?if (this.passwd !== this.lockPasswd) {
?? ??? ??? ??? ??? ?this.passwd = ''
?? ??? ??? ??? ??? ?this.$message({
?? ??? ??? ??? ??? ??? ?message: '解鎖密碼錯(cuò)誤,請(qǐng)重新輸入',
?? ??? ??? ??? ??? ??? ?type: 'error'
?? ??? ??? ??? ??? ?})
?? ??? ??? ??? ??? ?this.passwdError = true
?? ??? ??? ??? ??? ?setTimeout(() => {
?? ??? ??? ??? ??? ??? ?this.passwdError = false
?? ??? ??? ??? ??? ?}, 1000)
?? ??? ??? ??? ??? ?return
?? ??? ??? ??? ?}
?? ??? ??? ??? ?this.pass = true
?? ??? ??? ??? ?setTimeout(() => {
?? ??? ??? ??? ??? ?//輸入密碼正確后刪除vuex中狀態(tài)值
?? ??? ??? ??? ??? ?this.$store.commit('CLEAR_LOCK')
?? ??? ??? ??? ??? ?this.$router.go(-1); //返回上一層
?? ??? ??? ??? ?}, 1000)
?? ??? ??? ?}
?? ??? ?},
?? ??? ?components: {}
?? ?}
</script>

<style lang="scss">
?? ?.lock-container {
?? ??? ?height: 100%;
?? ??? ?display: flex;
?? ??? ?align-items: center;
?? ??? ?justify-content: center;
?? ??? ?position: relative;
?? ?}

?? ?.lock-container::before {
?? ??? ?z-index: -999;
?? ??? ?content: "";
?? ??? ?position: absolute;
?? ??? ?left: 0;
?? ??? ?top: 0;
?? ??? ?width: 100%;
?? ??? ?height: 100%;
?? ??? ?background-image: url("../../assets/images/lockLogin.png");
?? ??? ?background-size: cover;
?? ?}

?? ?.lock-form {
?? ??? ?width: 300px;
?? ?}
</style>

4.在路由中利用路由鉤子函數(shù)

import Vue from 'vue'
import Router from 'vue-router'
import util from '@/utils'
import store from '@/store'

router.beforeEach((to, form, next) => {
?? ?let user_token = util.getStore('user_token');
?? ?let toPath = to.path
?? ?console.log('toPath:', toPath)
?? ?console.log('在白名單中:', whiteList.indexOf(toPath));
?? ?console.log('user_token:', user_token)
?? ?document.body.scrollTop = 0
?? ?// firefox
?? ?document.documentElement.scrollTop = 0
?? ?// safari
?? ?window.pageYOffset = 0
?? ?if (whiteList.indexOf(toPath) == -1 && (!user_token && user_token !== undefined && user_token != null)) {
?? ??? ?//不在白名單,并且user_token沒有
?? ??? ?router.push({
?? ??? ??? ?path: '/login'
?? ??? ?})
?? ?} else if (whiteList.indexOf(toPath) != -1) {
?? ??? ?//去登錄頁(yè)
?? ??? ?// util.removeStore('user_token')
?? ??? ?next();
?? ?} else if (whiteList.indexOf(toPath) == -1 && user_token) {
?? ??? ?//不在白名單,并且user_token存在
?? ??? ?next()
?? ?}

?? ?/**
?? ? * 判斷鎖屏
?? ? */
?? ?if (store.getters.isLock && to.path !== '/lock') {
?? ??? ?next({
?? ??? ??? ?path: '/lock'
?? ??? ?})
?? ?}
});

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue使用screenfull實(shí)現(xiàn)全屏效果

    Vue使用screenfull實(shí)現(xiàn)全屏效果

    這篇文章主要為大家詳細(xì)介紹了Vue使用screenfull實(shí)現(xiàn)全屏,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • vue獲取或者改變vuex中的值方式

    vue獲取或者改變vuex中的值方式

    這篇文章主要介紹了vue獲取或者改變vuex中的值方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • Vue一個(gè)動(dòng)態(tài)添加background-image的實(shí)現(xiàn)

    Vue一個(gè)動(dòng)態(tài)添加background-image的實(shí)現(xiàn)

    這篇文章主要介紹了Vue一個(gè)動(dòng)態(tài)添加background-image的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • 基于Vue實(shí)例生命周期(全面解析)

    基于Vue實(shí)例生命周期(全面解析)

    下面小編就為大家?guī)硪黄赩ue實(shí)例生命周期(全面解析)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-08-08
  • vue中json格式化顯示數(shù)據(jù)(vue-json-viewer)

    vue中json格式化顯示數(shù)據(jù)(vue-json-viewer)

    這篇文章主要給大家介紹了關(guān)于vue中json格式化顯示數(shù)據(jù)(vue-json-viewer)的相關(guān)資料,Vue-json-viewer是一個(gè)Vue組件,用于在Vue應(yīng)用中顯示JSON數(shù)據(jù)的可視化工具,需要的朋友可以參考下
    2024-05-05
  • 有關(guān)vue 組件切換,動(dòng)態(tài)組件,組件緩存

    有關(guān)vue 組件切換,動(dòng)態(tài)組件,組件緩存

    這篇文章主要介紹了有關(guān)vue 組件切換,動(dòng)態(tài)組件,組件緩存,在組件化開發(fā)模式下,我們會(huì)把整個(gè)項(xiàng)目拆分成很多組件,然后按照合理的方式組織起來,達(dá)到預(yù)期效果,下面來看看文章的詳細(xì)內(nèi)容
    2021-11-11
  • vue element-ul實(shí)現(xiàn)展開和收起功能的實(shí)例代碼

    vue element-ul實(shí)現(xiàn)展開和收起功能的實(shí)例代碼

    這篇文章主要介紹了vue element-ul實(shí)現(xiàn)展開和收起功能的實(shí)例代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11
  • vue 掛載路由到頭部導(dǎo)航的方法

    vue 掛載路由到頭部導(dǎo)航的方法

    本篇文章主要介紹了vue 掛載路由到頭部導(dǎo)航的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-11-11
  • Vuex之module使用方法及場(chǎng)景說明

    Vuex之module使用方法及場(chǎng)景說明

    這篇文章主要介紹了Vuex之module使用方法及場(chǎng)景說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • Vue之版本升級(jí)后不兼容的問題及解決過程

    Vue之版本升級(jí)后不兼容的問題及解決過程

    本文將探討 Vue 版本升級(jí)后常見的不兼容問題,并提供相應(yīng)的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-03-03

最新評(píng)論

景洪市| 郑州市| 通化市| 改则县| 乌拉特前旗| 镇平县| 淮安市| 正镶白旗| 怀来县| 固阳县| 遂川县| 舒兰市| 隆子县| 彭州市| 武安市| 繁昌县| 三原县| 闽清县| 呼玛县| 德庆县| 阳高县| 郯城县| 枝江市| 白河县| 怀仁县| 尉犁县| 土默特右旗| 子洲县| 隆昌县| 洪洞县| 永丰县| 乌兰县| 闸北区| 华阴市| 四子王旗| 饶阳县| 五河县| 洱源县| 张掖市| 玉林市| 晋江市|