【发布时间】:2021-05-13 08:08:19
【问题描述】:
你好,当我尝试做一些苗条的模态时,我遇到了一个错误。
这是 App.svelte 的代码:
<script>
import Podcast from "./components/Podcast.svelte";
import Modal from 'svelte-simple-modal';
</script>
<style>
</style>
<main>
<Modal>
<Podcast color={"red"} title={"red"} />
</Modal>
<Podcast color={"green"} title={"green"} />
<Podcast color={"blue"} title={"blue"} />
<Podcast color={"purple"} title={"purple"} />
<Podcast color={"yellow"} title={"yellow"} />
<Podcast color={"brown"} title={"brown"} />
<Podcast color={"orange"} title={"orange"} />
</main>
这是我要处理点击的播客组件:
<script>
import { getContext } from 'svelte';
import ModalContent from './ModalContent.svelte';
export let title;
export let color;
const { open } = getContext('simple-modal');
const showModal= () => {
open(ModalContent);
};
</script>
<style>
section
{
width: auto;
display: flex;
justify-content: center;
align-items: center;
}
</style>
<section on:click={showModal} style="background-color: {color}">
The title is :
<b>
{title}
</b>
</section>
这里是我的模态内容(仅用于测试目的):
<script>
// your script goes here
</script>
<style>
/* your styles go here */
</style>
test test
我有这个错误:
Uncaught TypeError: Cannot destructure property 'open' of 'getContext(...)' as it is undefined.
有什么想法吗?
【问题讨论】:
-
getContext('simple-modal')里面有什么?我几乎可以肯定你那里没有物体。
标签: html css modal-dialog svelte