小编Ala*_*los的帖子

如何将嵌套数据结构作为 LitElement 中的属性传递?

在父组件中我有类似的内容:

render() => {
    const data = {a:1,b:[1,2,3]}; // of course this is a simplified version of the code
    return html`<child-component data=${data}></child-component>`
}
Run Code Online (Sandbox Code Playgroud)

这基本上相当于:

render() => {
    const data = {a:1,b:[1,2,3]}; // of course this is a simplified version of the code
    return html`<child-component data="[object Object]"></child-component>`
}
Run Code Online (Sandbox Code Playgroud)

基本上没什么用...

有没有一种简单的方法将复杂的对象层次结构传递到 litElement 组件中?

据我所知,我的选择是:

选项 1.使用属性:我是一个 litElement 菜鸟,所以我不确定这是否有效,并且我不确定如何使其工作而无需进行额外的函数调用。如果我能在里面做所有必要的工作就好了html

研究正在进行中。

选项 2.使用 Json。

将父组件中的对象字符串化

render() => {
    const data = {a:1,b:[1,2,3]}; // of course this is a simplified version …
Run Code Online (Sandbox Code Playgroud)

lit-element

0
推荐指数
1
解决办法
2022
查看次数

标签 统计

lit-element ×1