代码之家  ›  专栏  ›  技术社区  ›  opensas

通过编程访问苗条道具的价值

  •  0
  • opensas  · 技术社区  · 4 年前

    我有一个通过编程实例化的组件,如下所示:

    const form = new FormElement({
       target: options.el,
       props: { ...options },
    });
    

    我怎样才能得到道具的价值?差不多 form.props.editable form.$get('editable') 或类似

    谢谢

    1 回复  |  直到 4 年前
        1
  •  1
  •   brunnerh    4 年前

    看起来你要么需要设置 accessors 选项或从组件导出函数/对象:

    <!-- In the component -->
    <svelte:options accessors />
    

    然后直接访问 form.editable .

    您还可以从脚本块导出包装任何道具的函数/对象,例如。

    export function getEditable() { return editable }
    export const api = {
        get editable() { return editable; },
    };
    

    它们也可以直接调用( form.getEditable() / form.api.editable ).

    REPL with examples