How to execute a script when the custom element is upgraded

前端 未结 2 350
傲寒
傲寒 2020-12-10 13:17

I have defined a custom element and I want to execute a script only when the custom element is upgraded to its registered type. The use case is that I must call a custom met

2条回答
  •  有刺的猬
    2020-12-10 13:47

    Load the dependency via an import in your custom element module. For example, a custom element module (e.g.something.mjs) which depends on Highcharts:

    import '/node_modules/highcharts/highcharts.js'
    
    class Something extends HTMLElement {}
    
    customElements.define('x-something', Something)
    

提交回复
热议问题