英文:
svelte:component not displaying anything
问题
I'm trying to achieve a cde like in this repl:
https://svelte.dev/repl/16b375da9b39417dae837b5006799cb4?version=3.25.0
But I get an empty <div id="#printable"></div>
tab on my page
<script>
import { onMount } from 'svelte';
let Home;
onMount(async () => {
console.log('loading home ', doc.templateId)
switch (doc.templateId) {
case '1':
Home = await (import('$lib/template/_artist/Home.svelte')).default;
case '2':
case '3':
default:
Home = await (import('$lib/template/_expert/Home.svelte')).default;
}
console.log(' home loaded ', doc.templateId)
});
</script>
<div class='flex flex-col xl:flex-row'>
<ResumeButtons {data} />
<div class='flex flex-grow flex-row-reverse mt-4'>
<!-- //used to balance the growth of the buttons panel-->
</div>
<div id='printable' class='flex-none'>
<svelte:component this={Home} doc={doc} on:modified={documentModified}/>
</div>
</div>
In my console, I can see the component was loaded:
loading home 2
home loaded 2
I don't have any idea how I could debug what's going wrong
Just to validate the problem is not from the import path. If I import both templates, then write my code like follows, it works
import Expert from '$lib/template/_expert/Home.svelte';
import Artist from '$lib/template/_artist/Home.svelte';
//...
//then use it directly without await
//...
switch (doc.templateId) {
case '1':
Home = Artist;
break
case '2':
case '3':
default:
Home = Expert;
}
英文:
I'm trying to achieve a cde like in this repl:
https://svelte.dev/repl/16b375da9b39417dae837b5006799cb4?version=3.25.0
But I get an empty <div id="#printable"></div>
tab on my page
<script>
import { onMount } from 'svelte';
let Home;
onMount(async () => {
console.log('loading home ', doc.templateId)
switch (doc.templateId) {
case '1':
Home = await (import( '$lib/template/_artist/Home.svelte')).default;
case '2':
case '3':
default:
Home = await (import( '$lib/template/_expert/Home.svelte')).default;
}
console.log(' home loaded ', doc.templateId)
});
</script>
<div class='flex flex-col xl:flex-row'>
<ResumeButtons {data} />
<div class='flex flex-grow flex-row-reverse mt-4'>
<!-- //used to balance the growth of the buttons panel-->
</div>
<div id='printable' class='flex-none'>
<svelte:component this={Home} doc={doc} on:modified={documentModified}/>
</div>
</div>
In my console, I can see the component was loaded:
loading home 2
home loaded 2
I don't have any idea how I could debug what's going wrong
Just to validate the problem is not from the import path. If I import both templates, then write my code like follows, it works
import Expert from '$lib/template/_expert/Home.svelte';
import Artist from '$lib/template/_artist/Home.svelte';
//...
//then use it directly without await
//...
switch (doc.templateId) {
case '1':
Home = Artist;
break
case '2':
case '3':
default:
Home = Expert;
}
答案1
得分: 1
括号在导入语句中不正确吗?预期应为:
(await import('$lib/template/_artist/Home.svelte')).default
// 或者
await import('$lib/template/_artist/Home.svelte').then(m => m.default)
英文:
Aren't the parentheses at the imports wrong? Would expect:
(await import('$lib/template/_artist/Home.svelte')).default
// or
await import('$lib/template/_artist/Home.svelte').then(m => m.default)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论