引言

从0开始,写一个登录滑动解锁的功能。

首先,新创建一个 vue 项目。 或者在已有的项目写也可以。 将无用的代码删一下。

下载需要用到的组件库

1、下载 element-ui。

yarn add  element-ui -S   or   npm i element-ui -S

2、 在main.js 中引入。

    import Vue from 'vue'
    import App from './App.vue'
    import router from './router'
    import store from './store'
   import ElementUI from 'element-ui'  
   import 'element-ui/lib/theme-chalk/index.css'
    Vue.config.productionTip = false
   Vue.use(ElementUI)
    new Vue({
      router,
      store,
     el: '#app',
      render: h => h(App)
    }).$mount('#app')

3、测试是否下载成功。

<template>
  <div class="about">
      <el-button type="primary">主要按钮</el-button>
    <h1>This is an about page</h1>
  </div>
</template>

书写登录页面

页面可以正常展示按钮,说明下载成功。可以开始写代码了。

写一个简单的登录页面。

Login.vue

template 结构:

<template>
  <div class="login-container">
    <div class="login-header">
      <h1>xxx系统</h1>
    </div>
   <div class="login-body">
      <div class="login-form-container">
        <el-form
          ref="loginFormRef"
          class="form-style"
          :label-position="`right`"
          :model="loginFormData"
          status-icon
        >
          <el-form-item
            name="username"
            prop="username"
            >
            <el-input
              v-model="loginFormData.username"
              placeholder="请输入用户名"
              prefix-icon="el-icon-user"
              clearable
            />
          </el-form-item>
          <el-form-item
            class="el-item-style"
            name="password"
            prop="password"
          >
            <!-- 密码框 -->
            <el-input
              prefix-icon="el-icon-lock"
              v-model="loginFormData.password"
              :type="`${hasOpenEye? 'text':'password'}`"
              placeholder="请输入密码">
              <i
                slot="suffix"
                :class="[hasOpenEye ? 'el-icon-unlock' : 'el-icon-lock']"
                style="font-size: 14px; cursor: pointer"
                @click="hasOpenEye = !hasOpenEye"/>
            </el-input>
          </el-form-item>
          <el-form-item class="el-item-style">
            <el-button
              :loading="false"
              style="
                width: 100%;
                height: 46px;
                line-height: 15px;
                font-size: 23px;
              "
              type="primary"
              @click="login"
            >登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

script 逻辑:

<script>
export default {
  // 登录表单数据
  data () {
  return {
    loginFormData: {
      username: "123232",
      password: "21232"
    },
    hasOpenEye : false, // 是否显示密码
  }
  },
  components: {},
  methods: {
    login () {},
  },
}
</script>

style 样式:

<style lang="less" scoped>
.login-container {
  position: relative;
  height: 100%;
  width: 100%;
  display: flex;
  user-select: none;
  flex-direction: column;
  .login-header {
    display: flex;
    align-items: center;
    padding-left: 50px;
    cursor: pointer;
  }
  .login-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    color: #322b34;
    font-size: 12px;
  }
  .login-header,
  .login-footer {
    height: 10%;
  }
  .login-body {
    background-position: center center;
    background-repeat: no-repeat;
    background-size: 100% auto;
    flex: 1 1;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    .login-form-container {
      width: 30%;
      border: 1px solid mix(pink, #000, 80);
      box-shadow: 0 0.5em 1em rgba(0, 0, 0, 0.3);
      background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0.3),
        rgba(0, 0, 0, 0.3)
      );
      padding: 20px 30px;
      border-radius: 5px;
    }
  }
}
</style>

登录页面效果展示:

写滑动解锁组件

1、下载安装包:

vue-monoplasty-slide-verify

2、导入到 main.js 中

import SlideVerify from 'vue-monoplasty-slide-verify';
Vue.use(SlideVerify);

3、新建一个文件component / verify.vue

template 模板:

<template>
  <div>
    <!-- title="滑块验证码" -->
    <el-dialog
      :visible.sync="dialogVisible"
      :before-close="dialogBeforeClose"
      :close-on-click-modal="false"
    >
      <div class="flex">
        <slide-verify
          ref="slideblock"
          :w="fullWidth"
          :h="fullHeight"
          :accuracy="accuracy"
          :slider-text="text"
          :imgs="imgList"
          @again="onAgain"
          @fulfilled="onFulfilled"
          @success="onSuccess"
          @fail="onFail"
          @refresh="onRefresh"
        />
      </div>
    </el-dialog>
  </div>
</template>

script 代码:

<script>
export default {
  name: 'verify',
  data() {
    return {
      dialogVisible: false,
      fullWidth: 450,
      fullHeight: 304,
      msg: '',
      text: '请向右滑动滑块完成验证',
      // 精确度小,可允许的误差范围小;为1时,则表示滑块要与凹槽完全重叠,才能验证成功。默认值为5
      accuracy: 3,
      imgList: [
      // 图片的路径:
        require('../assets/3.jpg')
      ]
    }
  },
  mounted() {},
  methods: {
    dialogBeforeClose() {
      this.dialogVisible = false
    },
    onSuccess() {
      console.log('验证通过')
      this.msg = 'login success'
      this.dialogVisible = false
      this.$emit('verifySuccess')
       this.$message.success("验证成功")
       this.$router.push('/a')
    },
    onFail() {
      console.log('验证不通过')
      this.msg = '验证不通过'
        this.$message.error('验证失败')
    },
    onRefresh() {
      console.log('点击了刷新小图标')
      this.msg = ''
    },
    onFulfilled() {
      console.log('刷新成功啦!')
    },
    onAgain() {
      console.log('检测到非人为操作的哦!')
      this.msg = 'try again'
      // 刷新
      this.$refs.slideblock.reset()
    },
    handleClick() {
      // 父组件直接可以调用刷新方法
      this.$refs.slideblock.reset()
      console.log(23333);
    }
  }
}
</script>

style 样式:

<style lang="less" scoped>
.flex{
  display: flex;
  align-items: center;
  justify-content: center;
}
/deep/ .el-dialog {
  width: 500px;
  border-radius: 16px;
  margin: auto;
}
/deep/ .el-dialog__header {
  display: none;
}
/deep/ .slide-verify-slider {
  border-radius: 33px;
}
/deep/ .slide-verify-slider-mask {
  border-radius: 33px 0 0 33px;
}
</style>

将滑动组件运用到我们的 Login 组件中:

import verify from "../components/verify.vue";
export default {
 components: {
    verify
  },
}
<template>
   <el-form>
   ......
   </el-form>
  <verify ref="verify"></verify>
</template>

补充逻辑代码

login () {
      this.$refs.verify.dialogVisible = true
  },

最终效果:

完成。

以上就是vue 实现滑动块解锁示例详解的详细内容,更多关于vue 滑动块解锁的资料请关注Devmax其它相关文章!

vue 实现滑动块解锁示例详解的更多相关文章

  1. Vue如何指定不编译的文件夹和favicon.ico

    这篇文章主要介绍了Vue如何指定不编译的文件夹和favicon.ico,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  2. html5 canvas手势解锁源码分享

    这篇文章主要介绍了html5 canvas手势解锁源码分享,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  3. h5使用canvas画布实现手势解锁

    这篇文章主要介绍了h5使用canvas画布实现手势解锁的相关资料,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  4. ios – 锁定了多长时间Touch ID? “生物测量被锁定了.”

    >如果用户使用密码尝试失败,锁定触摸ID的时间是多少,或者我如何强行解锁呢?解决方法触摸ID一旦因不正确的尝试而被锁定,将被锁定,直到用户输入密码为止.所以没有固定的时间.解锁的唯一方法是从此时开始的密码,并且由于显而易见的原因,无法强制解锁.

  5. android – 应用内购买解锁付费功能

    我希望发布我的应用程序的两个版本:免费和付费.付费应用程序将具有更多功能,但没有额外的内容.最初我打算在市场上发布两个独立的应用程序,但事实证明,保留一个代码库并拥有两个独立的应用程序是很困难的.应用内购买是一种更好的方法吗?

  6. vue自定义加载指令v-loading占位图指令v-showimg

    这篇文章主要为大家介绍了vue自定义加载指令和v-loading占位图指令v-showimg的示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

  7. vue使用动画实现滚动表格效果

    这篇文章主要为大家详细介绍了vue使用动画实现滚动表格效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  8. 关于Vue 监控数组的问题

    这篇文章主要介绍了Vue 监控数组的示例,主要包括Vue 是如何追踪数据发生变化,Vue 如何更新数组以及为什么有些数组的数据变更不能被 Vue 监测到,对vue监控数组知识是面试比较常见的问题,感兴趣的朋友一起看看吧

  9. Vue子组件props从父组件接收数据并存入data

    这篇文章主要介绍了Vue子组件props从父组件接收数据并存入data的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  10. Vue h函数的使用详解

    本文主要介绍了Vue h函数的使用详解,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

随机推荐

  1. js中‘!.’是什么意思

  2. Vue如何指定不编译的文件夹和favicon.ico

    这篇文章主要介绍了Vue如何指定不编译的文件夹和favicon.ico,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  3. 基于JavaScript编写一个图片转PDF转换器

    本文为大家介绍了一个简单的 JavaScript 项目,可以将图片转换为 PDF 文件。你可以从本地选择任何一张图片,只需点击一下即可将其转换为 PDF 文件,感兴趣的可以动手尝试一下

  4. jquery点赞功能实现代码 点个赞吧!

    点赞功能很多地方都会出现,如何实现爱心点赞功能,这篇文章主要为大家详细介绍了jquery点赞功能实现代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  5. AngularJs上传前预览图片的实例代码

    使用AngularJs进行开发,在项目中,经常会遇到上传图片后,需在一旁预览图片内容,怎么实现这样的功能呢?今天小编给大家分享AugularJs上传前预览图片的实现代码,需要的朋友参考下吧

  6. JavaScript面向对象编程入门教程

    这篇文章主要介绍了JavaScript面向对象编程的相关概念,例如类、对象、属性、方法等面向对象的术语,并以实例讲解各种术语的使用,非常好的一篇面向对象入门教程,其它语言也可以参考哦

  7. jQuery中的通配符选择器使用总结

    通配符在控制input标签时相当好用,这里简单进行了jQuery中的通配符选择器使用总结,需要的朋友可以参考下

  8. javascript 动态调整图片尺寸实现代码

    在自己的网站上更新文章时一个比较常见的问题是:文章插图太宽,使整个网页都变形了。如果对每个插图都先进行缩放再插入的话,太麻烦了。

  9. jquery ajaxfileupload异步上传插件

    这篇文章主要为大家详细介绍了jquery ajaxfileupload异步上传插件,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  10. React学习之受控组件与数据共享实例分析

    这篇文章主要介绍了React学习之受控组件与数据共享,结合实例形式分析了React受控组件与组件间数据共享相关原理与使用技巧,需要的朋友可以参考下

返回
顶部