Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 共享相同属性的父web组件和子web组件_Javascript_Web Component_Lit Element_Lit Html - Fatal编程技术网

Javascript 共享相同属性的父web组件和子web组件

Javascript 共享相同属性的父web组件和子web组件,javascript,web-component,lit-element,lit-html,Javascript,Web Component,Lit Element,Lit Html,我正在尝试基于材质web组件mwc textfield创建自定义textfield web组件: 从'lit element'导入{LitElement,html,css}; 导入“@material/mwc textfield”; 导出类CustomTextfield扩展了LitElement{ 静态获取属性(){ 返回{ 标签:{type:String}, 必需:{type:Boolean}, 值:{type:String} } }; 获取值{ 返回这个.shadowRoot.getElem

我正在尝试基于材质web组件mwc textfield创建自定义textfield web组件:

从'lit element'导入{LitElement,html,css};
导入“@material/mwc textfield”;
导出类CustomTextfield扩展了LitElement{
静态获取属性(){
返回{
标签:{type:String},
必需:{type:Boolean},
值:{type:String}
}
};
获取值{
返回这个.shadowRoot.getElementById(“输入”).value;
};
构造函数(){
超级();
此标签为“”;
此值为“”;
这是必需的=false;
}
render(){
返回html`
`;
};
}
customElements.define('custom-textfield',CustomTextfield');

此时,我可以使用自定义textfield value_uu属性获取mwc textfield value属性。有没有办法通过自定义textfield值属性获取mwc textfield值属性?

要实现这一点,mwc textfield中的值属性应该是它的值,但在

所以,目前你不可能找到你想要的


但是无论如何,检查一下,他们讨论了未来可能实现的内部api来模拟表单元素,可以尝试
value=element.getAttribute('value')
import {LitElement, html, css} from 'lit-element';
import '@material/mwc-textfield';

export class CustomTextfield extends LitElement {

    static get properties() {
        return {
            label: {type: String},
            required: {type: Boolean},
            value: {type: String}
        }
    };

    get value_() {
        return this.shadowRoot.getElementById("input").value;
    };

    constructor() {
        super();
        this.label = "";
        this.value = "";
        this.required = false;
    }

    render() {
        return html`
            <mwc-textfield id="input"
                label="${this.label}"
                value="${(this.value === undefined) ? "" : this.value}"
                ?required="${this.required}"
                outlined
            >
            </mwc-textfield>
        `;
    };
}

customElements.define('custom-textfield', CustomTextfield);