vue3中登录滑动验证插件使用

安装依赖

npm install --save vue3-slide-verify

新建组件Slied

<template>
  <div class="silde_box">
    <slide-verify
    class="silde_box"
      ref="block"
      :slider-text="text"
      :accuracy="accuracy"
      @again="onAgain"
      @success="onSuccess"
      @fail="onFail"
      @refresh="onRefresh"
    ></slide-verify>
    <button class="btn" @click="handleClick">在父组件可以点我刷新哦</button>
    <div>{{ msg }}</div>
  </div>
</template>
 
<script lang="ts">
import { defineComponent, ref } from "vue";
// 局部注册组件,需要单独引用组件样式
// 只提供局部引用的方式,不再采用插件形式,方便按需加载,减少主包大小
import SlideVerify, { SlideVerifyInstance } from "vue3-slide-verify";
import "vue3-slide-verify/dist/style.css";
 
export default defineComponent({
  components: { SlideVerify },
 
  setup() {
    const msg = ref("");
    const block = ref<SlideVerifyInstance>();
 
    const onAgain = () => {
      msg.value = "检测到非人为操作的哦! try again";
      // 刷新
      block.value?.refresh();
    };
 
    const onSuccess = (times: number) => {
      msg.value = `login success, 耗时${(times / 1000).toFixed(1)}s`;
    };
 
    const onFail = () => {
      msg.value = "验证不通过";
    };
 
    const onRefresh = () => {
      msg.value = "点击了刷新小图标";
    };
 
    const handleClick = () => {
      // 刷新
      block.value?.refresh();
      msg.value = "";
    };
 
    return {
      block,
      msg,
      text: "向右滑动->",
      accuracy: 1,
      onAgain,
      onSuccess,
      onFail,
      onRefresh,
      handleClick,
    };
  },
});
</script>
<style scoped>
.silde_box{
  margin:0 auto;
}
</style>

父组件引用:

<template>
    <v-verify ></v-verify>
</template>
<script lang="ts">
import { defineComponent, onMounted, reactive, ref } from 'vue'
import slideVerify from "./components/slideVerify.vue";
 
export default defineComponent({
  components: {
    'v-verify':slideVerify
  }
})
</script>

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值