feat(custom): i

This commit is contained in:
2023-09-06 03:48:46 +08:00
parent 3b3cb7ba34
commit a9707c6d94
51 changed files with 2273 additions and 87 deletions

43
src/hooks/useScript.js Normal file
View File

@@ -0,0 +1,43 @@
import { onMounted, onUnmounted, ref } from 'vue'
export function useScript(opts) {
const isLoading = ref(false)
const error = ref(false)
const success = ref(false)
let script
const promise = new Promise((resolve, reject) => {
onMounted(() => {
script = document.createElement('script')
script.type = 'text/javascript'
script.charset = 'utf-8'
script.onload = function () {
isLoading.value = false
success.value = true
error.value = false
resolve('')
}
script.onerror = function (err) {
isLoading.value = false
success.value = false
error.value = true
reject(err)
}
script.src = opts.src
document.head.appendChild(script)
})
})
onUnmounted(() => {
script && script.remove()
})
return {
isLoading,
error,
success,
toPromise: () => promise,
}
}