《开源精选》是我们分享Github、Gitee等开源社区中优质项目的栏目,包括技术、学习、实用与各种有趣的内容。本期推荐的 captcha用于生成滑动验证码拼图图片和背景图片。
项目安装
npm i @itriton/captcha
使用方法
const captcha = require('@itriton/captcha')
// 默认(promise)
captcha.create().then(res=>{
console.log(res)
})
// 自定义参数(promise)
captcha.create(options).then(res=>{
console.log(res)
})
// 默认(async/await)
async function captcha(){
const result = await captcha.create()
}
// 自定义参数(async/await)
async function captcha(){
const result = await captcha.create(options)
}
参数设置
属性名 |
类型 |
默认值 |
说明 |
size |
Number |
30 |
默认拼图大小 |
width |
Number |
270 |
图片宽度(px) |
height |
Number |
144 |
图片高度(px) |
url |
String |
– |
图片路径(支持在线地址) |
结合 @itriton/uniapp 组件库的 行为验证(captcha)组件
快速上手
-
main.js引入iTriton库
// main.js
import itriton from '@itriton/uniapp';
Vue.use(itriton);
-
App.vue引入基础样式(注意style标签需声明scss属性支持)
/* App.vue */
<style lang="scss">
@import "@itriton/uniapp/index.scss";
</style>
-
uni.scss引入全局scss变量文件
/* uni.scss */
@import "@itriton/uniapp/theme.scss";
-
pages.json配置easycom规则(按需引入)
// pages.json
{
"easycom": {
// npm安装的方式不需要前面的"@/",下载安装的方式需要"@/"
// npm安装方式
"^t-(.*)": "@itriton/uniapp/components/t-$1/t-$1.vue"
// 下载安装方式
// "^t-(.*)": "@/@itriton/uniapp/components/t-$1/t-$1.vue"
},
// 此为本身已有的内容
"pages": [
// ......
]
}
使用方法
配置easycom规则后,自动按需引入,无需import组件,直接引用即可。
<template>
<t-date-picker></t-date-picker>
</template>
消息弹幕组件示例
基本使用
<t-barrage :list="list" :row="1">
<template v-slot:scope="{item}">
<view class="barrage">{{item.title}}</view>
</template>
</t-barrage>
—END—
更多内容:
https://gitee.com/ibaleine-open-source/itriton-captcha
原文始发于微信公众号(开源技术专栏):一款快速生成滑动验证码图片的项目
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/53868.html