File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed
web/src/components/clickCaptcha Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change 1- import { shortUuid } from '/@/utils/random'
21import { createVNode , render } from 'vue'
32import clickCaptchaConstructor from './index.vue'
4- import type { VNode } from 'vue '
3+ import { shortUuid } from '/@/utils/random '
54
65interface ClickCaptchaOptions {
76 // 验证码弹窗的自定义class
@@ -21,14 +20,18 @@ interface ClickCaptchaOptions {
2120 * @param options
2221 */
2322const clickCaptcha = ( uuid : string , callback ?: ( captchaInfo : string ) => void , options : ClickCaptchaOptions = { } ) => {
24- let vnode : VNode | null = createVNode ( clickCaptchaConstructor , {
23+ const container = document . createElement ( 'div' )
24+ const vnode = createVNode ( clickCaptchaConstructor , {
2525 uuid,
2626 callback,
2727 ...options ,
2828 key : shortUuid ( ) ,
29+ onDestroy : ( ) => {
30+ render ( null , container )
31+ } ,
2932 } )
30- render ( vnode , document . body )
31- vnode = null
33+ render ( vnode , container )
34+ document . body . appendChild ( container . firstElementChild ! )
3235}
3336
3437export default clickCaptcha
Original file line number Diff line number Diff line change 3939</template >
4040
4141<script setup lang="ts">
42- import { reactive , computed } from ' vue'
43- import { getCaptchaData , checkClickCaptcha } from ' /@/api/common'
42+ import { computed , reactive } from ' vue'
43+ import { checkClickCaptcha , getCaptchaData } from ' /@/api/common'
4444import { i18n } from ' /@/lang'
4545
4646interface Props {
@@ -85,6 +85,10 @@ const state: {
8585 },
8686})
8787
88+ const emits = defineEmits <{
89+ (e : ' destroy' ): void
90+ }>()
91+
8892const load = () => {
8993 state .loading = true
9094 getCaptchaData (props .uuid ).then ((res ) => {
@@ -123,7 +127,7 @@ const onCancelRecord = (index: number) => {
123127}
124128
125129const onClose = () => {
126- document . getElementById ( props . uuid )?. remove ( )
130+ emits ( ' destroy ' )
127131}
128132
129133const captchaBoxTop = computed (() => (state .captcha .height + 200 ) / 2 + ' px' )
You can’t perform that action at this time.
0 commit comments