当我尝试在本地执行Polymer元素时,我正在使用Polymer 3,并且我的HTML结构是HTML5。
counter-comp标签已添加到我的html文件中。
import {LitElement} from "@polymer/lit-element/lit-element.js"
class CounterComp extends LitElement{
constructor(){
super()
}
static get properties(){
return{
color:String,
background :String,
fontweight: String
}
}
_render({color,background,fontweight}){
return html`
<style>
.title{
background:$(background) ;
color: $(color);
font-weight:$(fontweight) ;
padding: 15px 25px;
}
</style>
<div class = "title">"This is in div tag with class title"</div>
`;
}
}
customElements.define("counter-comp",CounterComp);
<counter-comp color="green" background="blue" font-weight="355">
</counter-comp>
shady-render.ts:46未捕获的TypeError:result.getTemplateElement为 在渲染时不是结果函数(shady-render.ts:46) (shady-render.ts:130)在HTMLElement._applyRender (lit-element.ts:232)在HTMLElement._propertiesChanged (lit-element.ts:183)在HTMLElement._flushProperties (properties-changed.js?module:335)在HTMLElement._flushProperties (lit-element.ts:194)在HTMLElement.ready (properties-changed.js?module:179)在HTMLElement.ready (lit-element.ts:107)在HTMLElement._enableProperties (properties-changed.js?module:315)在HTMLElement.connectedCallback (properties-mixin.js?module:200)
我遇到上述错误,请检查并帮助解决此问题。
谢谢
答案 0 :(得分:0)
代替:
import {LitElement} from "@polymer/lit-element/lit-element.js"
使用:
import {LitElement, html} from "@polymer/lit-element/lit-element.js"