Skip to content

Commit 9bea107

Browse files
committed
update
1 parent d0c1b76 commit 9bea107

File tree

2 files changed

+118
-78
lines changed

2 files changed

+118
-78
lines changed

README.md

Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Vue 纯前端的拼图人机验证、右滑拼图验证<br/> 我知道有第 3
88
![img](public/demo.gif)
99

1010

11+
> 以下为Vue2.x使用文档
12+
> [Vue3.x的使用文档在这](README3.md)
13+
14+
1115
### 安装
1216

1317
```node
@@ -29,7 +33,7 @@ import Vcode from "vue-puzzle-vcode";
2933
到自己的项目里,给`app.vue`随便改个名字,就是个普通 vue 组件,直接用即可。<br/>
3034
`src/assets`里是一张小图片,`app.vue`中有引用,注意自己匹配一下引用路径
3135

32-
### Vue2.0 最简单例子
36+
### 最简单例子
3337

3438
```vue
3539
<template>
@@ -116,83 +120,6 @@ export default {
116120
域的图片
117121

118122

119-
<br/><br/>
120-
---
121-
122-
# 使用 Vue3.0
123-
<br/>
124-
125-
### 安装 vue3-puzzle-vcode
126-
```node
127-
npm install vue3-puzzle-vcode --save
128-
```
129-
130-
### Vue3.0 最简单例子
131-
```vue
132-
<template>
133-
<button @click="onShow">开始验证</button>
134-
<Vcode :show="isShow" @success="onSuccess" @close="onClose" />
135-
</template>
136-
137-
<script>
138-
import { ref } from "vue";
139-
import Vcode from "vue3-puzzle-vcode";
140-
export default {
141-
components:{
142-
Vcode
143-
},
144-
setup() {
145-
const isShow = ref(false);
146-
147-
const onShow = () => {
148-
isShow.value = true;
149-
};
150-
151-
const onClose = () => {
152-
isShow.value = false;
153-
};
154-
155-
const onSuccess = () => {
156-
onClose(); // 验证成功,需要手动关闭模态框
157-
};
158-
159-
return {
160-
isShow,
161-
onShow,
162-
onClose,
163-
onSuccess
164-
};
165-
}
166-
};
167-
</script>
168-
```
169-
170-
### Vue3.0 自定义图片
171-
```vue
172-
<template>
173-
<Vcode :imgs="imgs" />
174-
</template>
175-
176-
<script>
177-
import Img1 from "~/assets/img1.png";
178-
import Img2 from "~/assets/img2.png";
179-
180-
export default {
181-
setup(){
182-
const imgs = [Img1, Img2];
183-
184-
return {
185-
imgs
186-
}
187-
}
188-
};
189-
</script>
190-
```
191-
- 其他参数/事件都跟vue2.0一样
192-
193-
### Vue3.0源代码
194-
<a href="https://github.com/javaLuo/vue-puzzle-vcode/tree/vue3" target="_blank">https://github.com/javaLuo/vue-puzzle-vcode/tree/vue3</a>
195-
196123
### 说明
197124

198125
- 当不传递 imgs 字段或图片加载出错时,会自动生成随机图片

README3.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# vue3-puzzle-vcode [![npm](https://img.shields.io/npm/v/vue3-puzzle-vcode.svg)](https://www.npmjs.com/package/vue3-puzzle-vcode) [![npm downloads](https://img.shields.io/npm/dt/vue3-puzzle-vcode.svg)](https://www.npmjs.com/package/vue3-puzzle-vcode)
2+
3+
以下是在Vue3.0中使用的文档
4+
5+
**DEMO**: https://isluo.com/work/vue-puzzle-vcode/
6+
7+
![img](public/demo.gif)
8+
9+
10+
### Vue3.x 安装 vue3-puzzle-vcode
11+
12+
```node
13+
npm install vue3-puzzle-vcode --save
14+
```
15+
16+
### 使用
17+
18+
```vue
19+
import Vcode from "vue3-puzzle-vcode";
20+
21+
<Vcode :show="isShow" @success="onSuccess" @close="onClose" />
22+
```
23+
24+
### 最简单例子
25+
```vue
26+
<template>
27+
<button @click="onShow">开始验证</button>
28+
<Vcode :show="isShow" @success="onSuccess" @close="onClose" />
29+
</template>
30+
31+
<script>
32+
import { ref } from "vue";
33+
import Vcode from "vue3-puzzle-vcode";
34+
export default {
35+
components:{
36+
Vcode
37+
},
38+
setup() {
39+
const isShow = ref(false);
40+
41+
const onShow = () => {
42+
isShow.value = true;
43+
};
44+
45+
const onClose = () => {
46+
isShow.value = false;
47+
};
48+
49+
const onSuccess = () => {
50+
onClose(); // 验证成功,需要手动关闭模态框
51+
};
52+
53+
return {
54+
isShow,
55+
onShow,
56+
onClose,
57+
onSuccess
58+
};
59+
}
60+
};
61+
</script>
62+
```
63+
64+
### 参数
65+
66+
| 字段 | 类型 | 默认值 | 说明 |
67+
| ------------ | ------- | ------------------ | ----------------------------------------------------------------------------- |
68+
| show | Boolean | false | 是否显示验证码弹框 |
69+
| canvasWidth | Number | 310 | 主图区域的宽度,单位 px |
70+
| canvasHeight | Number | 160 | 主图区域的高度,单位 px |
71+
| puzzleScale | Number | 1 | 拼图块(小的拼图)的大小比例,0.2 ~ 2 ,数字越大,拼图越大 |
72+
| sliderSize | Number | 50 | 左下角用户拖动的那个滑块的尺寸,单位 px |
73+
| range | Number | 10 | 判断成功的误差范围,单位 px, 滑动的距离和拼图的距离小于等于此值时,会判定重合 |
74+
| imgs | Array | null | 自定义图片,见下方例子 |
75+
| successText | String | "验证通过!" | 验证成功时的提示文字 |
76+
| failText | String | "验证失败,请重试" | 验证失败时的提示文字 |
77+
| sliderText | String | "拖动滑块完成拼图" | 下方滑动条里的文字 |
78+
79+
### 事件
80+
81+
| 事件名 | 返回值 | 说明 |
82+
| ------- | ------ | ------------------------------------------------------------- |
83+
| success | 偏差值 | 验证通过时会触发,返回值是用户移动的距离跟目标距离的偏差值 px |
84+
| fail | 偏差值 | 验证失败时会触发,返回值同上 |
85+
| close | null | 用户点击遮罩层的回调 |
86+
87+
88+
### 自定义图片
89+
```vue
90+
<template>
91+
<Vcode :imgs="imgs" />
92+
</template>
93+
94+
<script>
95+
import Img1 from "~/assets/img1.png";
96+
import Img2 from "~/assets/img2.png";
97+
98+
export default {
99+
setup(){
100+
const imgs = [Img1, Img2];
101+
102+
return {
103+
imgs
104+
}
105+
}
106+
};
107+
</script>
108+
```
109+
110+
### 说明
111+
112+
- 当不传递 imgs 字段或图片加载出错时,会自动生成随机图片
113+
- 模态框的显示和隐藏完全由父级控制,所以用户通过验证后,需要手动隐藏模态框

0 commit comments

Comments
 (0)