Skip to content

Commit

Permalink
fix: 修复脚本加载方法判断错误
Browse files Browse the repository at this point in the history
  • Loading branch information
hacxy committed Mar 25, 2024
1 parent 0b5977b commit 666a20a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
27 changes: 9 additions & 18 deletions packages/oh-my-live2d/src/utils/index.ts
Expand Up @@ -78,26 +78,17 @@ export const createElement = (elConfig: ElementConfig): HTMLElement => {
* @returns
*/
export const loadScript = (sdkInfo: { url: string; id: string }): Promise<void> => {
// destroyElement(sdkInfo?.id);

return new Promise((resolve) => {
const el = document.getElementById(sdkInfo.id);
destroyElement(sdkInfo?.id);

if (el) {
el.addEventListener('load', () => {
resolve();
});
// resolve();
} else {
const scriptElement = document.createElement('script');

scriptElement.id = sdkInfo?.id;
document.head.append(scriptElement);
scriptElement.src = sdkInfo?.url;
scriptElement.addEventListener('load', () => {
resolve();
});
}
const scriptElement = document.createElement('script');

scriptElement.id = sdkInfo?.id;
document.head.append(scriptElement);
scriptElement.src = sdkInfo?.url;
scriptElement.addEventListener('load', () => {
resolve();
});
});
};

Expand Down
19 changes: 10 additions & 9 deletions tests/vite-app/src/main.ts
Expand Up @@ -143,15 +143,16 @@ const foo = async () => {
// setTimeout(() => {}, 10000);
// console.log(oml2d);
// oml2d.loadNextModel();
// const oml2d2 = await loadOml2d({
// models: [
// {
// path: 'https://registry.npmmirror.com/oml2d-models/latest/files/models/Senko_Normals/senko.model3.json',
// stageStyle: {},
// mobileScale: 0.08
// }
// ]
// });

await loadOml2d({
models: [
{
path: 'https://registry.npmmirror.com/oml2d-models/latest/files/models/Senko_Normals/senko.model3.json',
stageStyle: {},
mobileScale: 0.08
}
]
});

// setTimeout(() => {
// oml2d.loadNextModel();
Expand Down
8 changes: 5 additions & 3 deletions tests/vue-app/src/App.vue
@@ -1,13 +1,14 @@
<script setup lang="ts">
import { onMounted } from 'vue';
import { onMounted, ref } from 'vue';
import HelloWorld from './components/HelloWorld.vue';
import { loadOml2d } from 'oh-my-live2d';
const oml2d = ref();
onMounted(() => {
console.log('sssssssssssss');
loadOml2d({
parentElement: oml2d.value,
primaryColor: 'pink',
sayHello: true,
sayHello: false,
models: [
{
path: 'https://registry.npmmirror.com/oml2d-models/latest/files/models/Senko_Normals/senko.model3.json',
Expand Down Expand Up @@ -42,6 +43,7 @@ onMounted(() => {
<img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
</a>
<HelloWorld msg="Vite + Vue" />
<div ref="oml2d"></div>
</template>

<style scoped>
Expand Down

0 comments on commit 666a20a

Please sign in to comment.