niucloud/uni-app/hooks/useCaptcha.ts
全栈小学生 0e47055ccb v1.0.0-beta.1
2023-04-15 17:12:49 +08:00

28 lines
633 B
TypeScript

import { getCaptcha } from '@/api/system'
import { ref } from 'vue'
interface formData {
captcha_code: string,
captcha_key: string
}
export function useCaptcha(formData: formData) {
const image = ref('')
const refresh = async ()=> {
try {
const res:AnyObject = await getCaptcha()
if (res.code == 200) {
formData.captcha_key = res.data.captcha_key
formData.captcha_code = ''
image.value = res.data.img.replace(/\r\n/g, '')
}
} catch (e) {
}
}
return {
image,
refresh
}
}