fix(projects): 修复百度地图sdk地址

This commit is contained in:
Soybean
2021-11-09 23:49:24 +08:00
parent 6abe094ff2
commit 9a97d23c75
6 changed files with 15 additions and 57 deletions

View File

@ -7,7 +7,6 @@ import useRouteProps from './useRouteProps';
import useBoolean from './useBoolean';
import useLoading from './useLoading';
import useScrollBehavior from './useScrollBehavior';
import useScript from './useScript';
export {
useAppTitle,
@ -18,6 +17,5 @@ export {
useRouteProps,
useBoolean,
useLoading,
useScrollBehavior,
useScript
useScrollBehavior
};

View File

@ -1,45 +0,0 @@
import { onUnmounted } from 'vue';
import useLoading from './useLoading';
import useBoolean from './useBoolean';
export default function useScript(src: string) {
const { loading, startLoading, endLoading } = useLoading();
const { bool: isSuccess, setTrue: setIsSuccess, setFalse: setNotSuccess } = useBoolean();
let script: HTMLScriptElement;
function removeScript() {
if (script) {
script.remove();
}
}
function load() {
startLoading();
return new Promise((resolve, reject) => {
script = document.createElement('script');
script.type = 'text/javascript';
script.onload = () => {
endLoading();
setIsSuccess();
resolve('');
};
script.onerror = err => {
endLoading();
setNotSuccess();
reject(err);
};
script.src = src;
document.head.appendChild(script);
});
}
onUnmounted(() => {
removeScript();
});
return {
loading,
isSuccess,
load
};
}