Vue.js圖片滑動驗證的實現(xiàn)示例
有些網(wǎng)站為了防止有人惡意使用腳本進行批量操作,會設(shè)置前后端進行配合的圖片滑動驗證,本文這里只介紹前端的驗證功能。
這里可以直接使用 vue-monoplasty-slide-verify 這個庫組件,效果演示如下:
開始使用
庫組件下載:
npm install --save vue-monoplasty-slide-verify
main.js中引入全局組件SlideVerify:
import SlideVerify from "vue-monoplasty-slide-verify"; Vue.use(SlideVerify);
使用組件:
<template> <!-- 遮罩層 --> <div class="mask"> <div class="slideContainer"> <slide-verify @success="onSuccess" @fail="onFail" @refresh="onRefresh" @fulfilled="onFulfilled" slider-text="向右滑動驗證"> </slide-verify> <div style="margin-top: 15px;">{{ text }}</div> </div> </div> </template> <script> export default { data () { return { text:'' } }, methods:{ onSuccess(times){ this.text = '驗證通過,耗時 '+ (times / 1000).toFixed(1) + '秒' }, onFail(){ this.text = '驗證失敗' }, onRefresh(){ //點擊刷新按鈕 this.text = '' }, onFulfilled() { //驗證失敗自動刷新 this.text = '重新驗證' }, } } </script> <style scoped> .mask { position: fixed; left: 0%; top: 0%; width: 100%; height: 100%; z-index: 100; overflow: hidden; background-color: rgba(0, 0, 0, 0.5); } .mask .slideContainer { position: absolute; left: 50%; top: 50%; background-color: rgb(255, 255, 255); transform: translate(-50%,-50%); padding: 15px; } </style>
組件對應(yīng)的參數(shù)和回調(diào)函數(shù):
tips: 當(dāng)參數(shù)imgs不傳或者傳空數(shù)組時,圖片庫默認使用第三方api提供的圖片路徑,可能加載緩慢。
到此這篇關(guān)于Vue.js圖片滑動驗證的實現(xiàn)示例的文章就介紹到這了,更多相關(guān)Vue.js圖片滑動驗證內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue3實現(xiàn)HTML內(nèi)容預(yù)覽功能
這篇文章主要為大家詳細介紹了如何使用Vue3實現(xiàn)HTML內(nèi)容預(yù)覽功能,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2025-03-03Vue讀取本地靜態(tài)文件json的2種方法以及優(yōu)缺點
這篇文章主要介紹了Vue讀取本地靜態(tài)文件json的2種方法以及優(yōu)缺點說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09vue3(ts)類型EventTarget上不存在屬性value的問題
這篇文章主要介紹了vue3(ts)類型EventTarget上不存在屬性value的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03vue2.0與vue3.0及vue與react的區(qū)別及說明
這篇文章主要介紹了vue2.0與vue3.0及vue與react的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10