[英]How to pass parameter to modal in svelte
Hello I need your help because I use modal in my svelte app but I need to pass parameter to the modal component to choose what I wrote inside of it.您好,我需要您的帮助,因为我在我的苗条应用程序中使用模态,但我需要将参数传递给模态组件以选择我在其中编写的内容。 But in the open() function of Modal we just need to give the component we imported so I don't know how to pass the parameter.
但是在 Modal 的 open() function 中我们只需要给出我们导入的组件所以我不知道如何传递参数。
Here some code I have:这里有一些代码:
import { getContext } from 'svelte';
import ModalContent from './ModalContent.svelte';
export let title;
const { open } = getContext('simple-modal');
const showModal = () => {
open(ModalContent);
};
But I would like something like this:但我想要这样的东西:
import { getContext } from 'svelte';
import ModalContent from './ModalContent.svelte';
export let title;
const { open } = getContext('simple-modal');
const showModal = () => {
open(<ModalContent texte={title} />);
};
It looks like you're using the svelte-simple-modal component.看起来您正在使用svelte-simple-modal组件。 In that case, you'll want to pass the props as an object to the second argument of the
open()
function.在这种情况下,您需要将道具作为 object 传递给
open()
function 的第二个参数。
import { getContext } from 'svelte';
import ModalContent from './ModalContent.svelte';
export let title;
const { open } = getContext('simple-modal');
const showModal = () => {
open(ModalContent, {texte: title});
};
See the documentation for more information.有关更多信息,请参阅文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.