【发布时间】:2021-05-22 00:13:58
【问题描述】:
我有一个苗条的文件,它以字符串格式(HTML 标记)获取数据:
<script>
import { onMount } from 'svelte';
import { loadData } from '../stores.js';
let content
onMount(async() => {
content = await loadData();
})
</script>
我随后将这些数据附加到页面:
<div>
{#await content}
<p>waiting for content...</p>
{:then content}
{@html content}
{/await}
<h1>Test heading</h1>
</div>
但是即使有样式:
<style>
h1 {
font-size: 5rem;
font-style: oblique;
}
p {
font-size: 2rem;
font-style: oblique;
}
</style>
转换为 html 的附加字符串显然不是用适当的类生成的:
<div class="svelte-1a8cxpf">
<h1 class="svelte-1a8cxpf">Test heading</h1>
<h1>Appended heading - not styled</h1> <!-- here is no style -->
</div>
有什么办法,如何让样式也非分类项目,或者说在那个特定的 svelte 文件中创建更通用的 css 规则?
【问题讨论】:
标签: svelte