繁体   English   中英

Polymer 2.0中的factoryImplementation

[英]factoryImplementation in Polymer 2.0

在Polymer 1.0中,可以检测是否由构造器创建了聚合物元素,当创建该元素时触发的函数名为factoryImpl()。

我不会在Polymer 2.0中做同样的事情,如果我通过构造函数创建了一个元素,则应该触发一个标准函数并且应该做一些事情。 有没有人做过此事并且可以给出提示呢?

非常感谢

您可以使用构造函数:

class TestEle extends Polymer.Element {
      static get is() { return 'test-ele'; }
      constructor() {
        super()
        console.log('created')
      }
//...

每当您创建TestEle时,您都应该看到“创建”已记录

<test-ele> </test-ele> // created
or 
document.createElement('test-ele') // created
or
new TestEle() // created

//根据以下评论进行编辑。

我找不到与2.0中旧版factoryImpl等效的任何信息。 但是,您可以尝试以下工作。

class TestEle extends Polymer.Element {
      static get is() { return 'test-ele'; }
      constructor(c) {
        super()
        console.log('created')
        if(c) {
           console.log('created using constructor')
        }
      }
...
<test-ele> </test-ele> // created
or 
document.createElement('test-ele') // created
or
new TestEle(true) // created and created using constructor

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM